Help wanted ! PLease explain what is try and catch use for .
Tom Salo
Greenhorn
Joined: Oct 28, 2002
Posts: 7
posted
0
As the topic said, Could anyone please explain what is try and catch in Java means please. Also is that the catch always will be use after we use try ? e.g try { // Some code here } catch { // Some Code here }
James Chegwidden
Author
Ranch Hand
Joined: Oct 06, 2002
Posts: 201
posted
0
Try /catch is used to handle exceptions.
Try must always be in tandem with either a catch and/or a finally. It cannot be alone.
Mr. C<br /> <br />Author and Instructor<br />My book:<br /><a href="http://www.aw-bc.com/catalog/academic/product/0,1144,1576761614,00.html" target="_blank" rel="nofollow">http://www.aw-bc.com/catalog/academic/product/0,1144,1576761614,00.html</a>
Cindy Glass
"The Hood"
Sheriff
Joined: Sep 29, 2000
Posts: 8521
posted
0
Try means "execute the following code. If there is a problem look in the associated catch blocks to see how to handle the problem" Catch means "if this is the problem that you ran into, this is what you should do about it". Normally this includes formatting some sort of message to the user or the console.
"JavaRanch, where the deer and the Certified play" - David O'Meara
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
posted
0
When I began to learn about Exceptions in Java, I read (and reread a few times):