aspose file tools*
The moose likes Java in General and the fly likes shall we put rich information in customized exception ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "shall we put rich information in customized exception ?" Watch "shall we put rich information in customized exception ?" New topic
Author

shall we put rich information in customized exception ?

ben oliver
Ranch Hand

Joined: Mar 28, 2006
Posts: 370
Suppose I have a customized exception for my project --

public class CustomerException extends Exception {
public Customerxception() {}

public CustomerException(String msg) {
super(msg);
}
}

In my code, whatever checked standard exception I catch, I do

throw new CustomerException(" some messge here...");

to throw to client side a "CustomerException". Fairly simple. The question is -- Shall I put "rich" information in the argument of "CustomerException" ? i.e shall I do things like

throw new CustomerException("Backend Error"); // short version msg

or

throw new CustomerException("There is a backend database error happended when table" + table + "is being updated by client " + client);

How do you guys usually do ?

The CustomerException is thrown to my client side code.

Thanks.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

As usual, it depends. Show the user as much information as they need to know. But for logging I tend to get as detailed as I can without going overboard.


GenRocket - A Test Data Generation Platform
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
Certainly a preference (and possibly desired to be localized), but I like to be detailed and offer a way around the problem or a possible cause.

/snark-asm/
Or, if you're done acquiring Yahoo, you could politely throw an exception 41850, which could easily be cross referenced in the user handbook.


Bill Shirley - bshirley - frazerbilt.com
if (Posts < 30) you.read( JavaRanchFAQ);
ben oliver
Ranch Hand

Joined: Mar 28, 2006
Posts: 370
Then after the client side catches "CustomerException", is it going to really check the e.getMessage() to see what's the message ? I thought usually when client gets the "CustomerException" it just does something mechanically. If you put rich and detailed information into the Exception constructor, does it mean you want client to check this messge and do different things according to the different messages ? If that;s the case, are you going to hard-coded the client code like

if (e.getMessage().equals("This is a database error")
// go to databse error page
if(e.getMessage().equals("This is a input error")
// go to input error page
...

This sounds crazy.. Maybe my understanding is wrong. Please tell me how client can really use the "messge" embedded in the exception constructor.

Thanks.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
Originally posted by ben oliver:

if (e.getMessage().equals("This is a database error")
// go to databse error page
if(e.getMessage().equals("This is a input error")
// go to input error page
...

This sounds crazy.. Maybe my understanding is wrong. Please tell me how client can really use the "messge" embedded in the exception constructor.

Thanks.
If that sort of thing happens, you are better with CustomerDatabaseException, CustomerInputException, etc, etc
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
It has been my experience that most people do not want all the information I tend to give. I suggest putting up an explaination on the console that most people could interpret as something wint arrrohng.

Put things like jump table indexes or technical trace-log messages in a log file so the tech that is trying to fix it can inform supervisor where the problem is. Don't let exception catching become bulky, but put something there that can be used to trace the matter.


"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: shall we put rich information in customized exception ?
 
Similar Threads
Design Issues
Problem handling exceptions in client side
NX: URLy Bird 1.3.1 Explicit Fatal Exception Handling
Struts2 customized Exception handler
how to handle the exception for JUnit code