This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes IllegalStateException in delete/update Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "IllegalStateException in delete/update" Watch "IllegalStateException in delete/update" New topic
Author

IllegalStateException in delete/update

Paweł Baczyński
Bartender

Joined: Apr 18, 2013
Posts: 837
    
  14

Is it a good idea to throw IllegalStateException from delete and update methods when invoked on an unlocked record?
The interface doesn't mention this exception. But... ISE is an unchecked exception so it doesn't need to me mentioned.
What do you think?


Formely Pawel Pawlowicz
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5122
    
  12

I used IllegalArgumentException and IllegalStateException quite extensively in my application.


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Paweł Baczyński
Bartender

Joined: Apr 18, 2013
Posts: 837
    
  14

Suppose null was passed to createRecord(String[] record)
Which is better? NullPointerException or InvalidArgumentException?
I'd use InvalidArgumentException because it is more specific.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5122
    
  12

I used IllegalArgumentException for that purpose. But the Java classes (like String) uses NullPointerException: Unless otherwise noted, passing a null argument to a constructor or method in this class will cause a NullPointerException to be thrown.
 
wood burning stoves
 
subject: IllegalStateException in delete/update
 
Similar Threads
Why throw an RecordNotFoundException in your unlock method?
[B&S] - Delete & Unlock Questions
Problem with unlock method with wrong lockCookie
Do I need to catch any of these exception in my code ?
SecurityException