File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Efficient Try Catch

 
Joe Deluca
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey everybody!

I was just wondering which is more efficient, a try/catch in the method, or try/catch the actual method. Such as:



or


What are your thoughts?
Thanks, Joe
 
Campbell Ritchie
Sheriff
Pie
Posts: 47262
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It all depends what the method is doing, what sort of Exception it throws, and what you want to do with it. Are you inside a loop which can be repeated when whatever goes wrong has been sorted out? Do you have to close your app if there is an Exception?

But simply writing "return;" in a catch block is very inefficient. The most you will achieve like that is hiding errors; an Exception you know about is not dangerous. An Exception you don't know about, because it is consumed silently, can be very dangerous because you might be calculating "wrong" answers and not know about it. At least print a message so you know what has happened.





And you thought I would say "no 1" or "no 2"!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic