• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

The best way to use Exceptions in catch block?

 
Ranch Hand
Posts: 214
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all Ranchers,

I have a query for the Exception.

What is the best way to use of the Exception?

means if we are define a particular Exception in a catch block like
catch(SQLException sl){
sl.printStatckTrace();}
catch(ClassNotFoundException ce){
ce.printStatckTrace();}
catch(IOException ex){
ex.printStatckTrace();}

and in the last
catch(Exception e){
e.printStatckTrace();}


Is this wrong way to use catch(Exception e){e.printStatckTrace();} after a specified exception.

Is this wrong then correct me.

and if we are using only for all type of exception then is it sufficient
catch(Exception e){
e.printStatckTrace();}



Thanks in advanced!!.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Rd,

its good practice to seperate all possible cases in seperate catch block(try to cover all types of exception don't use Exception class). and instead of using printStatckTrace()
use Logger class to print your exception in console.
and don't forget to use finally for query to close your connection, resultset, statement objects.
 
Rd Dari
Ranch Hand
Posts: 214
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rajesh,

Its a good answer which I wanted.

Thanks for a early and good reply
 
Rajesh Pattabi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome Rd
 
I didn't like the taste of tongue and it didn't like the taste of me. I will now try this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic