Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception Handling

 
Sushma Bhat
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have thought about exceptions for my assignemnt and would like to know if I am on the right track.


My assignment throws two unchecked exceptions RecordNotFoundException and
DuplicateKeyException and says the following

"Any unimplemented exceptions in this interface must all be created as member classes of the suncertify.db package. Each must have a zero argument constructor and a second constructor that takes a String that serves as the exception's description.

Any methods that throw RecordNotFoundException should do so if a specified record does not exist or is marked as deleted in the database file."
****************************************************************************
This is what I intend to do ...

FOR GIVEN EXCEPTIONS :
1. Create a RecordNotFoundException extending RunTimeExceptions and handle only Record not found exceptions

2. Create a DuplicateKeyException extending RunTimeExceptions and handle only Record not found exceptions

3.CHECKED exceptions :

Create AllOtherExceptions extending Exception and handle all other exceptions in here .
some thing like
catch(Exception ex) {
throw new AllOtherExceptions ("UNEXPECTED EXCEPTION");
}

4.Other RunTime Exceptions : Do Nothing.

*************************************************

Does this strategy cover all the requsite things ...

Thanks for your time.
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why did you decide to make those unchecked exceptions?
They're possible results of the business process, therefore should be checked exceptions.
 
Sushma Bhat
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>>>why did you decide to make those unchecked exceptions?
They're possible results of the business process, therefore should be checked exceptions.

So how do I handle checked exceptions ..just catch them and exit with an appropriate message .?

I was planning to catch them at a single place and exit
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depends on the severity.
If there's an error writing to the database because someone else has locked the record in the meantime, just say so and go on.
If the database is down, say that and pop up the connection dialog so the user can try to reconnect (or connect to another database elsewhere).

Neither scenario would warrant killing the client application.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic