aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Catching exception question 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 "Catching exception question" Watch "Catching exception question" New topic
Author

Catching exception question

Leandro Melo
Ranch Hand

Joined: Mar 27, 2004
Posts: 401
Hi, if try to catch something that cannot be thrown from anywhere, I'll have an unreachable code and an compile error. For instance, this code gives me a compile error.


I understand this fine. But when you don't use Exception subclasses, the following code compiles fine. In other words, if you try to catch Exception base class, it's fine, it doesn't generate compile errors.


Can anyone clarify this behaviour for me?


Leandro Melo
SCJP 1.4, SCWCD 1.4
Adam Czysciak
Ranch Hand

Joined: Feb 25, 2005
Posts: 90
    
    5
Originally posted by Leandro Melo:
In other words, if you try to catch Exception base class, it's fine, it doesn't generate compile errors.


Can anyone clarify this behaviour for me?[/QB]


Sure ;-) You can catch any unchecked exceptions at any time. RuntimeException and it's subclasses are instanceof Exception, therefore you can catch it. The same applies to Error and its subclasses. And, obiously, you could also try to catch Throwable.


Adam
SCJA, SCJP 5.0, SCWCD 1.4, SCBCD 5, SCEA 5
Leandro Melo
Ranch Hand

Joined: Mar 27, 2004
Posts: 401
Sure! Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Catching exception question