• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception vs IOException

 
Sanjeev Singh
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Priya Viswam
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sanjeev Singh
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Priya,Thanks for clarifying.
 
Ramya Chowdary
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
not throwing a checked Exception in a declared Try block is compiler error.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic