• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

exception handling

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
To do a great right, do a little wrong - shakepeare. twisted little ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic