Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

exception handling

 
deepak mehta
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic