File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes JVM - Programatically thrown Exceptions 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 "JVM - Programatically thrown Exceptions" Watch "JVM - Programatically thrown Exceptions" New topic

JVM - Programatically thrown Exceptions

palla sridhar
Ranch Hand

Joined: Oct 15, 2007
Posts: 111
According to Objective 2.6 of K&B, some exceptions are thrown by the JVM and some PROGRAMATICALLY.
1. Can anyone explain how one can say that a particular EXCEPTION is thrown by JVM or thrown PROGRAMATICALLY?
2. Also though it is out of scope of SCJP, how can we decide about CHECKED exceptions, whether they're thrown by JVM or PROGRAMATICALLY ?

Thanks and Regards,
*Nothing is CONSTANT in life, except CHANGE*
Doug Slattery
Ranch Hand

Joined: Sep 15, 2007
Posts: 294
Hi Palla,

Here, PROGRAMATICALLY means checked, which also means caught at compile time. There are cases for exceptions to occur which cannot be caught by the compiler due to (bad?) object states at runtime. A good example of this would be in file i/o where you try to open a file for reading that doesn't exist. The compiler doesn't know the file doesn't exist, whence at runtime, an unchecked exception is thrown.

Hope this helps. I was a little confused about this too when I started K&B (I think my eyes were glazed over at the time ). There'll be other references to checked/unchecked exceptions further in the book.


-- Nothing is impossible if I'mPossible
[ October 18, 2007: Message edited by: Doug Slattery ]
palla sridhar
Ranch Hand

Joined: Oct 15, 2007
Posts: 111
Hi Doug!
Thank you for the explanation. But if you see K&B, there are some RUNTIME exceptions like IllegalArgumentException,IllegalStateException, and NumberFormatException and an AssertionError which all come under UNCHECKED.
It is given in the book, that all these are throws PROGRAMATICALLY..

But as you said,
Here, PROGRAMATICALLY means checked.
how can these be throws PROGRAMATICALLY if they're unchecked ??
ravi satti

Joined: Oct 16, 2007
Posts: 13

I dont know if there is any way to know whether a exception is thrown by JVM or Programmatically. But as the answer to your 2nd question i can make a below statement.

An exception thrown Programmatically can be either checked or unchecked, but any exception thrown by JVM is unchecked.
I agree. Here's the link:
subject: JVM - Programatically thrown Exceptions
It's not a secret anymore!