jQuery in Action, 2nd edition*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Can someone help me? I think my exceptions may be wrong but need opinion (B&S) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Can someone help me? I think my exceptions may be wrong but need opinion (B&S)" Watch "Can someone help me? I think my exceptions may be wrong but need opinion (B&S)" New topic
Author

Can someone help me? I think my exceptions may be wrong but need opinion (B&S)

Yucca Nel
Ranch Hand

Joined: Nov 20, 2008
Posts: 147

I have the following exceptions and would like opinions on them.

In my Database I have a super exception DatabaseException this is the parent class for all DatabaseExceptions and I have coded the provided interface exceptions from DB.java as subclasses of this exception. DatabaseException extends Exception.

In my server I have a Business Exception which once again is subclass of Exception but a super class to all business layer exceptions like..
RecordNotFoundException
BookedRecordException

I also have a final SystemException which is a subclass of RuntimeException and gets thrown when any error that can cause a serious problem occurs.

Do these exception classes sound ok?


SCJP 6.0, SCJD (400/400), SCBCD for JEE 5, SCWCD 1.4 I do videos for development at
http://www.youtube.com/user/thejartender?feature=mhee
I am probably the only developer ever to have had an orange sized brain tumor in my brain while learning development!!
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2242
    
    7

Personally, it looks to me you have too many exceptions. Think from the client side, how many exceptions do the client code need to catch?

I'm doing URLyBird, and I use a service layer between database and client. I have 2 exceptions (DatabaseException and RemoteException from RMI or some server exception if you like) to worry about at the end. My DB interface has 2 exceptions: RecordNotFoundException and DuplicateKeyException. In my service layer I catch these then throw my DatabaseException.

Talking about RuntimeException why need to have a SystemException? Are you planning to throw runtime exception?

Also I don't recommend making the exceptions from DB interface a subclass of your own DatabaseException or Java's exception subclass such as IOException. Just make it subclass Exception will be fine. This is because the behavior may be different.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5
Yucca Nel
Ranch Hand

Joined: Nov 20, 2008
Posts: 147

Thank you... I need to redo them(exceptions) I think.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can someone help me? I think my exceptions may be wrong but need opinion (B&S)
 
Similar Threads
Single Data Interface Justification
Local & Remote Data Intefaces
FBN : Exception in High level Data Interface
Exception Handling
A bit confused on my choice of a Database Eception...