aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exception vs IOException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exception vs IOException" Watch "Exception vs IOException" New topic
Author

Exception vs IOException

Sanjeev Singh
Ranch Hand

Joined: Nov 01, 2006
Posts: 381
While writing some codes I obseved that

compiles fine while

gives
C:\nbworkspace\FlowControl\src\TestException.java:6: exception java.io.IOException is never thrown in body of corresponding try statement
}catch(IOException e){
1 error
BUILD FAILED (total time: 0 seconds)

I was under a impression that the Program#1 should also fail.Can anyone make it out why the Program#1 compiles.


~Sanjeev Singh<br />SCJP 1.5
Priya Viswam
Ranch Hand

Joined: Dec 28, 2006
Posts: 81
Summary for try-catch without throwing exception:

�Catching Throwable, Error (including its subclasses), Exception, and RuntimeException (including its subclasses) always compile.
�Catching directly subclasses of Throwable except for Exception and Error will generate a compile time error.
�Catching subclasses of Exception except for RuntimeException will generate a compile time error.


SCJP 1.5<br />SCWCD 1.4
Sanjeev Singh
Ranch Hand

Joined: Nov 01, 2006
Posts: 381
Priya,Thanks for clarifying.
Pratap koritala
Ranch Hand

Joined: Sep 27, 2006
Posts: 252
not throwing a checked Exception in a declared Try block is compiler error.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception vs IOException