Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » J2EE Interest »

Re: Exception handling

Frans Verhoef

2005-10-23

Replies:

Hi,
Whether you lose stacktrace information depends on whether it's an exception you rethrow as a DataInvalidException, or it's an Exception you throw yourself. As you do it now, the exception, once thrown, will have a stacktrace starting from the place where you throw the Exception.
If you catch an existing exception, and then rethrow the exception as a DataInvalidException, then you should implement the constructor with String and Throwable parameters.
For example:

public DataInvalidException(String message, Throwable t){
 super(message, t);
}

which you can use like this:

try{
  //  your code that might throw some Exception
}catch(Exception e){
 throw new DataInvalidException("Data is invalid", e);
}

Cheers,
Frans

On Sun, 23 Oct 2005 17:46:57 -0600, SUBSCRIBE EJB-INTEREST anonymous wrote:
> Hi,
> I have an class derived from Exception and have one
> constructor,which takes only a String as parameter.
> In my application, I just use the below line to throw the
> exception.Is this correct?Since, exception object is not passed to
> the constructor, will I lose any stacktrace information?
>
>
> throw new DataInvalidException("Datais invalid");
>
> Thanks in advance,
>
> ======================================================================
> ===== To unsubscribe, send email to listserv@(protected)
> include in the body of the message "signoff J2EE-INTEREST".  For
> general help, send email to listserv@(protected)
> the body of the message "help".

===========================================================================
To unsubscribe, send email to listserv@(protected)
of the message "signoff J2EE-INTEREST". For general help, send email to
listserv@(protected)".
©2008 junlu.com - Jax Systems, LLC, U.S.A.