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..
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
I am probably the only developer ever to have had an orange sized brain tumor in my brain while learning development!!
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.