This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes RunTimeException or checked Exception? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "RunTimeException or checked Exception?" Watch "RunTimeException or checked Exception?" New topic

RunTimeException or checked Exception?

Anders Hermansen

Joined: Nov 15, 2007
Posts: 6

on page 370 in K & B book on SCJP they write that NumberFormatException is a exception typically thrown programmatically.

But is it not a RuntimeException? And therefore thrown by the JVM?

(Just for case of clearness: in the table on same page is it right to say that exceptions thrown by JVM are RunTimeExceptions and programatically exceptions are checked exceptions?)
Saroja Eshwar

Joined: Oct 26, 2007
Posts: 10

Even i am not able to figure it out which exceptions are thrown by JVM and which are thrown by API developer..

Please help us out...

Kelvin Chenhao Lim
Ranch Hand

Joined: Oct 20, 2007
Posts: 513
The "programmatic-vs-JVM" distinction isn't the same as "checked-vs-unchecked". Here's something I posted a few weeks ago that may help:

I'm not a fan of the term "thrown programmatically" as a supposed contrast to "thrown by the JVM". In my opinion, it's much clearer to think of it as "thrown explicitly" (a.k.a. "programmatically") versus "thrown implicitly" (a.k.a. "by the JVM").

Using this terminology, an "explicitly thrown" exception is one that can only be thrown in Java code using a "throws" or "assert" statement, i.e. there must be some expression of programmer intent to (possibly) cause an exception at that point. On the other hand, an "implicitly thrown" exception is one that can occur even in expressions that have neither a "throws" or "assert". Most of these are the result of abruptly completed evaluations, e.g. dereferencing a null reference or an integer division by zero.

Hopefully this way of differentiating exceptions will help some of you. Also, it may be helpful to read what the JLS has to say about the causes of exceptions.

SCJP 5.0
subject: RunTimeException or checked Exception?
It's not a secret anymore!