Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception

 
luk Hann
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Could anybody give me a clear shot when I should expect to use "try-catch" to handle exception, when "throws" and when both? Thanks.
Luk
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should use try/catch anytime you are about to execute some code that might run into trouble. For instance if you are about to divide by an integer variable there is always the chance that the variable will hold a zero and cause and arithmeticException. And IO causes all sorts of problems and you should deal with it so your program does not crash. The classes that might cause trouble Implement or extend some sort of Exceptions.
Once you catch an Exception it is up to you whether to deal with it (print out a cute message, ask the user for better input, etc.) or throw it to a super class to deal with (like when you have not a clue how to deal with the problem or are just to lazy).
[This message has been edited by Cindy Glass (edited February 02, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic