Meaningless Drivel is fun!
The moose likes Beginning Java and the fly likes exception handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "exception handling" Watch "exception handling" New topic

exception handling

deepak mehta

Joined: Jan 25, 2005
Posts: 15
hello group members
sir i want to know abt exception handling in java
1.what is diffrence between finally and catch is it similar to desturctor like fianlize ?
2.why always run finally if exception not occur?
3.clear me the meaning of implement runnable class through thread

deepak kr.
Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
Ok, those are some pretty different questions you have there...

The finally clause is what you want to execute whether or not an exception occurs. Like if you have opened a stream and you're reading bytes, then whether or not there's an exception (something goes wrong), you still want to try to close the stream, so you put that in the finally clause.

Here's the source on the subject:

This article might also interest you:

I don't think it's really comparable to a destructor.

As for the Thread vs. Runnable debate, that has been discussed
here. If you Google around, you'll find other discussions. Here's Sun's discussion of the matter:
Nikhilesh Fonseca
Ranch Hand

Joined: Aug 23, 2004
Posts: 57
1.what is diffrence between finally and catch is it similar to desturctor like fianlize ?

Finalize is not a destuctor as we have in C++ but it does give a programmer the last chance to do anything before an object is lost..Garbage collected
It also provides the programmer the a chance to ressurest the object i.e recreate the same ..but this can only be doen once.

As regards to threads
You may create threads by either extending the thread class or Implementing the runnable interface both of which will provide arun method through which you can do your Processing
Consider Paul's rocket mass heater.
subject: exception handling
jQuery in Action, 3rd edition