• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

What kind of Exception should I catch

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I just confused with what kind of Exception should I catch. Need I to catch it at all time for all kinds of exceptions? Take some exceptions for example. The SQL Exception I have to write a catch part every time when i use execute() in PreparedStatement , but the start() in Thread also throw a IllegalThreadStateException but my eclipse says nothing.


why they both throws exception but treated differently.
[ October 07, 2007: Message edited by: Xavier Lio ]
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Checked exceptions" are exceptions that the compiler "checks" to make sure you've taken precautions against -- either catch them or declare them. "Unchecked exceptions" are not checked by the compiler, so it's up to you whether to deal with them.

Checked exceptions include java.lang.Exception and all of its subclasses other than RuntimeException and its subclasses.

For example, SQLException directly extends Exception, so it is checked. The compiler requires that you catch or declare it. But IllegalThreadStateException extends Runtime exception, so it is unchecked.
 
Xavier Lio
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply...

but i don`t absolutely agree with you after i had read the source code of thread and PreparedStatement.

in Thread the start() is like this



sure it throws a exception said in comment, but not with a throws part. so May I conclude that the native method don`t throw a exception obviously or that the exceptions without a throws declare don`t need a catch part.


still wait for you reply .. and many thanks for your help..

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Xavier,

IllegalThreadStateException is an unchecked exception check

IllegalThreadStateException
as "Marc" mentioned that for unchecked exception we are not forced by compiler to handle.
 
Something about .... going for a swim. With this tiny ad ...
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic