File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Yucca Nel
Ranch Hand
Posts: 147
IntelliJ IDE Java Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
K. Tsang
Bartender
Pie
Posts: 3222
12
Android Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Yucca Nel
Ranch Hand
Posts: 147
IntelliJ IDE Java Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you... I need to redo them(exceptions) I think.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic