• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Exceptions doubt

 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
still confused a little bit
 
Eduardo Mendes
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic