Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why should not caught Exception

 
pooja jain
greenhorn
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I know that this is not recommended , but what exactly the reason ?
In which situation , it is recommended ?
In K&B book it is given that , you will not get proper message ( log ) if you will use this , I am not getting why ?
e.printStackTrace() will be called based on object ( Exception ) type ( late binding ) , so I think we will get proper message .

please help me .
Thanks in advance .
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One reason may be this : In real project , we never just write printStackTrace() method in a catch block , we do something specific depends on exception type .

Like if there is FileNotFoundException then we can provide any local file . So we catch exception separately & do something specific for them .

In which situation , it is recommended ?

Well , I don't think , it is recommended in any situation .
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic