• Post Reply Bookmark Topic Watch Topic
  • New Topic

Question of clarification...on definition of Exception  RSS feed

 
Bob Ruth
Ranch Hand
Posts: 320
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working my way through HFJ, to get my Java skills up and ran across a term "bandied about" that I never saw specifically defined, at least not yet. I have my suspicions and just wanted to air them here and see if I was right.

I have seen references in the book and on here for that matter to "checked exceptions" and "unchecked exceptions".

Is it just simply stated that:

1) checked exceptions are exception conditions that can be caught by the compiler, and

2) unchecked exceptions are exception conditions that must be caught by the JVM at run-time?

If ol' "Grasshopper" needs more patience you can tell me that too!!! Meaning..... it may be defined in HFJ and I just need to wait until I get there...

Thanks, gang!
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, all exceptions get thrown and caught while the program is running, not while its being compiled.

Checked exceptions are those which the compiler will insist you include a catch clause for, and insist that methods throwing them must declare them in a "throws" clause.

Unchecked exceptions are those the compiler doesn't care about. You can still use a catch clause for them, but the compiler won't force you; if you don't, your exception may then terminate the thread it's thrown in, and/or exit your program.

How does the compiler know which is which? Unchecked exceptions are subclasses of java.lang.Error or java.lang.RuntimeException. Checked exceptions are subclasses of java.lang.Exception (excepting RuntimeException and its subclasses.)
 
Bob Ruth
Ranch Hand
Posts: 320
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks very much for the excellent answer. I knew I was in the right place!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!