wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in exception scenarios Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt in exception scenarios" Watch "Doubt in exception scenarios" New topic
Author

Doubt in exception scenarios

Sumit Bisht
Ranch Hand

Joined: Jul 02, 2008
Posts: 329

I've got a doubt in exception types (pg. 370 table 5-2 of K&B book) It mentions exceptions as thrown by the jvm or the program.
Is there any link between these and compile time/run time exceptions or is there a difference in the handling of such exception-causing code!
Please voice your comments as I've got more confused after reading this topic.
Jamie MacDonald
Greenhorn

Joined: May 17, 2008
Posts: 20
Compile time errors are a completely different beast. If your code won't compile, you can't run it so you will never get any exceptions of any sort.

The Errors and Exceptions referred to in that table are all run time events. In some cases they may be the result of faulty program logic, but the code must have compiled to get you that far.

In your every day coding, Exceptions thrown programmatically are typically the ones you will need to handle. However in the case of the table you referenced, all of the Exceptions are RuntimeExceptions and therefore none of them need to be checked. Errors do not need to be checked either, so nothing in the table is subject to the "handle or declare" rule.

So in the case of the table, the distinction between what is thrown programmatically and what is thrown by the JVM can only be stated as specifically as the section on page 367 (K&B Java 5) called "Where Exceptions Come From". The distinction is in the words "thrown explicitly" in the description of programmatic exceptions. This means that somewhere in your Java code or in the Java code that you are calling (including the code in the Java API) there is actually a line of code that says "throw Xxx", where Xxx is the Exception listed in the left column of the table.

[As an aside, the Java 6 version of K&B is out and has sufficient revisions to make the page numbers different. It would be helpful to note which edition of the book you are referencing.]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Doubt in exception scenarios