• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

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

 
Ranch Hand
Posts: 147
IntelliJ IDE Java Ubuntu
  • 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?
 
Bartender
Posts: 3648
16
Mac OS X Firefox Browser Java
  • 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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you... I need to redo them(exceptions) I think.
 
Power corrupts. Absolute power xxxxxxxxxxxxxxxx is kinda neat.
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic