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

Doubt in exception scenarios

 
Ranch Hand
Posts: 331
Python Ruby Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.]
 
What a stench! Central nervous system shutting down. Save yourself tiny ad!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic