• 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

Exception Handling

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic