aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes EXCEPTION problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "EXCEPTION problem" Watch "EXCEPTION problem" New topic
Author

EXCEPTION problem

Maduranga Liyanage
Ranch Hand

Joined: May 25, 2005
Posts: 124
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

Joined: May 24, 2005
Posts: 45
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

Joined: May 25, 2005
Posts: 124
Hi Lalitha..

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

Thanks..
karan wadhwani
Greenhorn

Joined: Feb 22, 2005
Posts: 12
class EOFException extends Exception {
public EOFException() {}
public EOFException(String msg) {
super(msg);
}
}
Lalitha Gottumukkula
Ranch Hand

Joined: May 24, 2005
Posts: 45
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

Joined: Aug 19, 2003
Posts: 182
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..


Thnx
soumya ravindranath
Ranch Hand

Joined: Jan 26, 2001
Posts: 300
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

Joined: Mar 14, 2003
Posts: 810
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 ??/


Thanks and Regards, Amit Taneja
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EXCEPTION problem