File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exceptions doubt

 
Mamadou Touré
Ranch Hand
Posts: 189
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ??

Regards
 
Eduardo Mendes
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Hemnathbabu Kottaiveedu
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

From SCJP exam point of view if you want to remember the exception type you can use this tip:

Following are the exceptions thrown programatically:

IllegalArgumentException

NumberFormatException(Subclass of IllegalArgexp)

IllegalStateException and

AssertionError (This is simple to remember)


All other 6 exceptions are thrown by JVM.

Hope this helps you.
 
Mamadou Touré
Ranch Hand
Posts: 189
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
still confused a little bit
 
Eduardo Mendes
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic