• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in Exception Handling.

 
N.Senthil Kumar
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Say for example,

i am closing a InputStream Object, the Compiler says Handle IOException.

May I know which is best and why..
whether to catch Exception or IOException .

That is Specific Exception or General Base Exception.

Thanks
 
Rob Spoor
Sheriff
Pie
Posts: 20661
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you know exactly which exceptions can be thrown, try to catch the specific ones as much as possible. If you catch Exception you may catch a NullPointerException or IllegalArgumentException you weren't expecting.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12196
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you may also catch an exception that is (better) handled elsewhere.
 
N.Senthil Kumar
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks.

Will Catch Exception.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50171
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
N.Senthil Kumar wrote: . . . Will Catch Exception.
So you haven't taken any notice of the replies?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic