File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Exceptiopn handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Exceptiopn handling" Watch "Exceptiopn handling" New topic

Exceptiopn handling

Smitha Prasad
Ranch Hand

Joined: Apr 02, 2002
Posts: 41
during exception ahndling is it required to handle it? i.e must it be caught? And what is the difference in using checked exceptions and normal exceptions?
Smitha Prasad
Ranch Hand

Joined: Apr 02, 2002
Posts: 41
what is the difference in using throw and try?
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
These are very basic questions. You can either search this forum or check out the Java tutorial at Sun's site. OTOH, any descent textbook should have them explained.

So much trouble in the world -- Bob Marley
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
"try" means "check out the following piece of code" and if it has a problem find the appropriate catch block and follow those instructions." You will know if it had a problem, because it will throw an exception if it does.
"throw" means "a problem has been found and I am going to deal with it by creating an exception object that explains the whole thing and throwing it to the class that called me and hope that that class that has a better idea of what to do with this - since I don't have any good advice". Of course as a rule you end up catching an exception that a lower level class has thrown to you and you have to decide what to do about it.
If your class DOES have some good advice, then it can handle the exception itself by catching the exception and dealing with it - or it can deal with it by re-throwing it (hopefully with a better message or whatever).

"JavaRanch, where the deer and the Certified play" - David O'Meara
Saif Ullah

Joined: Mar 21, 2002
Posts: 29
The difference between checked and unchecked exceptions is that, in case of checkecked exceptions you have to either handle them or leave the handling explicitly to the caller.
In case of unchecked exceptions, these exceptions has been implicitly handled by the default Exception Handler of the JVM, that is why the programmer is not required to handle them explicitly.
with regards

A java Student
saif ullah
Smitha Prasad
Ranch Hand

Joined: Apr 02, 2002
Posts: 41
thanks cindy and saif
I agree. Here's the link:
subject: Exceptiopn handling
It's not a secret anymore!