Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EXCEPTION problem

 
Maduranga Liyanage
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can somebody please tell me why I get the compile error saying that EOFException is not found in class exception_test when I have imported Throwable ??? I know this code doesn't make any sense, but I'm just trying to test throwing exceptions..


[ June 02, 2005: Message edited by: Barry Gaunt ]
 
Lalitha Gottumukkula
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.lang.Throwable is the super class of all errors and exceptions in the Java language. Importing this class will not import all the exceptions of Java.

EOFException is in java.io package. Try importing this package.

Thanks,
Lalitha.
 
Maduranga Liyanage
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Lalitha..

It worked.. Thanks a lot!!!
But isn't every exception that can be thrown is under Throwable??

Thanks..
 
karan wadhwani
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class EOFException extends Exception {
public EOFException() {}
public EOFException(String msg) {
super(msg);
}
}
 
Lalitha Gottumukkula
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exactly.

All exception classes are subtypes of class Exception. This class derives from the class Throwable (which derives from the class Object). Hence, there are two subclasses that derive from Throwable: Exception
and Error. Thus, all the exceptions that are thrown will be somewhere in this Throwable hierarchy.

Thanks,
Lalitha.
 
Nischal Tanna
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All the Exception classes are derived from java.lang.Throwable. But that dosent mean they are in the same package !!!... The child classes are in different packages... simple..
 
soumya ravindranath
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Maduranga Liyanage:
Hi Lalitha..

It worked.. Thanks a lot!!!
But isn't every exception that can be thrown is under Throwable??

Thanks..


Are you confusing extending a class with using a class by importing the appropriate package ? If you do not import the required Exception class, the compiler cannot locate it. This is in no way related to the class you have imported even though it happens to be the super class.
It's a different case when it comes to using try-catch construct. If you use Exception class in catch, it will catch any exception that is derived from Exception.
 
amit taneja
Ranch Hand
Posts: 813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Maduranga Liyanage:
Can somebody please tell me why I get the compile error saying that EOFException is not found in class exception_test when I have imported Throwable ??? I know this code doesn't make any sense, but I'm just trying to test throwing exceptions..



[ June 02, 2005: Message edited by: Barry Gaunt ]




what should be import to make this class run..??

is we have to import exceptions every time we use them ?

i think java.util.* is included in every program by default but does that means that only clases comming under java.util will be implicitly accessable ??/
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic