I found in several mock exams the question gives a list of exceptions and asks to say which ones are programmer's and which ones are JVM's. So is there a simple way to distinguish them, or should I know them by heart ??
SCJP 5 (76%)
SCWCD 5 (86%)
"The greatest glory in living lies not in never falling, but in raising every time we fall.".. Nelson Mandela
You can find some background on this in the K&B book, pages 368-369. Personally, I also struggled sometimes to distinguish ones from the others.
Anyway. This is how I understand it. A programmer exception is one created specifically to address a program-logic situation (e.g. you get the arguments into your method not formatted properly, or you define a new type of exception to deal with a special/exception case in your application's logic). On the other hand, a NullPointerException is the typical JVM exception, which is not related to any particular program-logic situation, but rather raises an issue the JVM encountered when trying to execute the program.
A bit confusing, I admit, but hope this helps somehow.
This is a good example of a JVM exception: java.lang.NullPointerException
A good example of a programmer exception: com.mypackage.UserNotLoggedIn
I try to distinguish ones from the others by looking at the JVM exceptions as generic exceptions, that do not relate to any particular failure in the program logic, and to the programmer exceptions as exceptions created to signal a specific error related to the program logic.
e.g. - a NullPointerException signals that the JVM tried to invoke a method on a reference that points to null - a com.mypackage.UserNotLoggedIn was created by the programmer to signal that a certain anonymous user tried to do an operation which requires him to be logged in.