wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes GUI Exceptions - bubbled Business exceptions or new ones? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "GUI Exceptions - bubbled Business exceptions or new ones?" Watch "GUI Exceptions - bubbled Business exceptions or new ones?" New topic
Author

GUI Exceptions - bubbled Business exceptions or new ones?

Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

Howdy Ranchers!

I'm close to start working with networking and GUI of my application and started to wonder, what is the desired way of GUI handling and throwing exceptions?
I mean, I've got 3 layer application, and I was thinking that if the record is not found - I could use the RecordNotFoundException which is thrown from the URLyBird service class (which is bubbled from the underlying Data class which really throws it).

Should the RecordNotFoundException be thrown in the GUI, or perhaps BusinessException should be thrown instead with description saying what's wrong?

Then again, I would like to inform user that the room he wants to book has already been booked by another user, so I can:
- Create new exception like RoomAlreadyBookedException (which will be thrown only from service layer, and cought only by GUI layer)
- Use BusinessException - mentioned above - and set appropriate message.

As I like the main idea of Business Exceptions, I don't really like the idea of putting reasons in the exception message. It's OK if I want to show the user very generic information what happened in a form of alert window with message of exception as it's content. But what if I would like to present user a different error window, for example a YES/NO dialog - I would end up with matching exception message strings to see if it is the right communicate or not. This idea feels like a VERY bad idea.

So if I end with creating new BLL/GUI Exceptions (like RoomAlreadyBookedException) what about RecordNotFoundException. Should I reuse the one from Data class, or to be strict, should define something like RoomNotFoundException in BLL/GUI which would wrap the RecordNotFoundException?

What should be the desired design?

Also, did you inform user that there was a problem with initializing record's cache (during some storage media exception)?
If yes, than what the user could do in this situation?

What is your opinion?

Cheers!


OCP Java SE 6 Programmer, OCM Java SE 6 Developer, OCE Java EE 6 JSPSD, OCE Java EE 6 EJBD, OCE Java EE 6 JPAD, Spring 3.0 Core Professional.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 4907
    
  10

In my business layer I catch the exceptions from the database layer, and throw specific business exceptions instead. In the controller (in my client) all these business exceptions are caught and wrapped in a GUIException with an appropriate (and understandable) message for the user. And this message is shown in an error dialog to the user.

If there is a problem during server startup (in networked mode) or the client application (in networked mode or standalone mode) the user is informed by an appropriate message (depending on the error: server does not exist, database file is invalid, ...) and the application finally exits.


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
 
Consider Paul's rocket mass heater.
 
subject: GUI Exceptions - bubbled Business exceptions or new ones?
 
Similar Threads
Design Question for MVC
[URLyBird 1.3.1] Just download, some questions!
Handling checked and unchecked Exceptions?
Handling Exceptions in Business Layer
Handling Runtime Exceptions and Fatal Checked Exceptions in the Client