aspose file tools*
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "exception handling" Watch "exception handling" New topic
Author

exception handling

deepak mehta
Greenhorn

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:
http://java.sun.com/docs/books/tutorial/essential/exceptions/

This article might also interest you:
http://www.onjava.com/pub/a/onjava/2003/11/19/exceptions.html

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:
http://java.sun.com/docs/books/tutorial/essential/threads/clock.html
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: exception handling
 
Similar Threads
What is the exact use of a finally block in exception handling?
java [question -- exception handling]
Try - catch & finally
Exception Handling - Good Practice
Checking connection status