Win a copy of OCP Oracle Certified Professional Java SE 11 Developer Practice Tests this week in the OCP forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
Sheriffs:
  • Devaka Cooray
  • paul wheaton
  • Mark Herschberg
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
  • Jj Roberts
Bartenders:
  • Carey Brown
  • salvin francis
  • Piet Souris

Exception

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am confused at the checked/unchecked Exception.
How can I know which one is the checked Exception
need to catch in the program, and which one is
the unchecked Exception needn't to catch in the
program.
thanks
Krussi
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Checked exceptions are any classes that extend the exception class, excluding the class RuntimeException. RuntimeException and its descendents make up the set of unchecked exceptions. Note that the class Exception, itself, is an unchecked exception.
I hope that helps,
Corey
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As Corey has explained checked and unchecked exceptions are based on the fact what exception class do they extend. SO to figure out whether to catch an exception in program or not you have to traverse the hierarchy to see if its an RunTime Exception or is in subtree of exception class (not under checked exception subtree - user defined exception).
You will have to refer to documentation to find out about pre-defined exceptions and further the API documentation should indicate about the exceptions the API throws.
hope that was helpful
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't forget the java.lang.Error Class -- it's decendents are also not checked.
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jessica Sant:
Don't forget the java.lang.Error Class -- it's decendents are also not checked.


But don't get errors confused with exceptions. The class Error and Exception are siblings. Errors are not exceptions and vice versa. Each class extends Throwable.
But, like Jessica said, Errors are unchecked.
Corey
 
krussi rong
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks very much!
Krussi
 
Too many men are afraid of being fools - Henry Ford. Foolish tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic