-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: What kind of error messages to display to the user?
PostPosted: Tue Sep 02, 2003 5:36 am 
Regular
Regular

Joined: Tue Aug 26, 2003 6:59 pm
Posts: 89
Location: Somewhere in the Ghetto
what kind of error messages should I display to users when non-recoverable exceptions are thrown from Session most methods? (subclasses of HibernateException, list below)

CacheException, CallbackException, IdentifierGenerationException, InstantiationException, JDBCException, MappingException, ObjectDeletedException, ObjectNotFoundException, PersistentObjectException, PropertyAccessException, QueryException, SerializationException, StaleObjectStateException, TransactionException, TransientObjectException, ValidationFailure, WrongClassException


some exceptions like ObjectNotFound, I catch and send messages back to the user but what about the rest?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 02, 2003 11:18 pm 
Newbie

Joined: Tue Aug 26, 2003 9:59 am
Posts: 19
Location: Atlanta, GA
Generally, I would not show any of these to the user (depending on who the user is). You want to have exceptions be appropriate for the level of abstraction. If there is no way that the caller will no how to handle the low-level Hibernate exceptions, then nest those exceptions in a higher-level PersistenceException of your own. For a more thorough treatise on exception handling; check out this JavaWorld series.

_________________
Bill Siggelkow


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 03, 2003 3:23 am 
Regular
Regular

Joined: Tue Aug 26, 2003 6:59 pm
Posts: 89
Location: Somewhere in the Ghetto
the exceptions being thrown by hibernate would be wrapped by an upper-level in my case so I would not directly show the hibernate exception, something like this:

try {
UserManager.saveUser(user);
} catch(ManagerDuplicateIdException mdie) {
// user name already taken show somekind of error telling user to re-input a // different username
} catch(ManagerException me) {
// some other error, could be a JDBCException, StaleObjectException, I dont //know but what kind of error or message should I give the user?
}


in this case I have ManagerDuplicateIdException a subclass of ManagerException, the UserManager.saveUser() method throws just ManagerException

maybe im doing something else worng here and just have a bad design to start off with, maybe someone could help me out here with my approach


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 03, 2003 8:51 am 
Newbie

Joined: Tue Aug 26, 2003 9:59 am
Posts: 19
Location: Atlanta, GA
What you may want to do is create something like

ManagerServiceException extends ManagerException to handle this case. For your user, all he needs to know is that the service failed in a way that he has no recourse for (as opposed to the duplicate ID where you can display an appropriate message to try a different idea). For the ManagerServiceException you may want to provide ability to view detail (the wrapped HibernateException), e-mail this error to support, etc.

_________________
Bill Siggelkow


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 03, 2003 11:29 am 
Regular
Regular

Joined: Tue Aug 26, 2003 6:59 pm
Posts: 89
Location: Somewhere in the Ghetto
ok, ill take your advice, I was already logging the exceptions the app wasnt able to recover from, and i'll just send a message to the user telling them "some unknown error occured" or something along those lines, but that isnt very helpfull to the user.

is there anything I can do to prevent any of these un-recoverable exceptions from being thrown at all? or are most of these exceptions caused programming errors?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 03, 2003 11:51 am 
Newbie

Joined: Tue Aug 26, 2003 9:59 am
Posts: 19
Location: Atlanta, GA
Well, you could change these "unrecoverable" exceptions into RuntimeExceptions -- that way you don't have to declare them. Regardless, you should log the errors in either case.

It kind of depends on your application -- if its a web app, then throwing a RuntimeException will result in a 500 (server) error -- you can create an error page to show a "prettier" page to the user on a server error.

If you are using something like Struts -- this is a good opportunity to investigate the use of declarative exception handling. You could define a global exception handler for your base exception that could declare a "prettier" page (or even a whole different workflow) and provide as much or as little detail as you desire.

_________________
Bill Siggelkow


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.