• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JVM - Programatically thrown Exceptions

 
palla sridhar
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Doug Slattery
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Aloha,
Doug

-- Nothing is impossible if I'mPossible
[ October 18, 2007: Message edited by: Doug Slattery ]
 
palla sridhar
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ??
and
 
ravi satti
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic