This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exception" Watch "Exception" New topic
Author

Exception

luk Hann
Ranch Hand

Joined: Jan 29, 2001
Posts: 48
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

Joined: Sep 29, 2000
Posts: 8521
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).]


"JavaRanch, where the deer and the Certified play" - David O'Meara
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception