File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Exceptions" Watch "Exceptions" New topic
Author

Exceptions

Surya Bavirti
Greenhorn

Joined: Sep 08, 2008
Posts: 13
how can i identify CheckedExceptions&UncheckedExceptions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38481
    
  23
To the Java Tutorials! There you find that unchecked Exceptions have RuntimeException (or Error) as a superclass, and checked Exceptions don't have RuntimeException (or Error) as a superclass.
Gamini Sirisena
Ranch Hand

Joined: Aug 05, 2008
Posts: 347
Why would a programmer want to check this?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38481
    
  23
Because the compiler insists checked Exceptions be declared or caught, but it doesn't insist for unchecked Exceptions.
Because most unchecked Exceptions require corrections to the code if they occur.
Surya Bavirti
Greenhorn

Joined: Sep 08, 2008
Posts: 13
By seeing anexception, how can i identify wether the exception is a super class of RuntimeException? or not?i'm new to to Java
Gamini Sirisena
Ranch Hand

Joined: Aug 05, 2008
Posts: 347
Campbell, I mean the last query Surya has posted.. why would Surya want to check this?

mmm.. sorry messed up..

I guessed that Surya wanted to check whether a Throwable object was of type Exception or Error or RuntimeException. What is the use of that to a programmer?
[ September 29, 2008: Message edited by: Gamini Sirisena ]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38481
    
  23
You don't usually test what type an Exception is; you usually try to anticipate it (if there is a checked Exception notified you must anticipate it). The throws clause of any methods you call or its Javadoc or both should tell you what sort of Exceptions it throws, and you set up appropriate catch blocks for those types, always starting with the most specific (subtype) and ending with the most general (supertype).

If you insist on testing the type of a specific Exception object you can use the instanceof operatorbut I have never seen anything like that written, nor would I regard that as good programming.
Surya Bavirti
Greenhorn

Joined: Sep 08, 2008
Posts: 13
Thanks to Sirisena & Campbell.now i got an idea about Exceptions.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38481
    
  23
You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exceptions