Re: How can I throw an Exception of another type from...
Posted By:
Bill_Siggelkow
Posted On:
Friday, February 16, 2001 10:42 AM
A typical way of doing this is to provide a wrapper exception (similar to RemoteException) that encapsulates the root or "caused by" exception. The encapsulating exception can have a method to get the caused by exception and may also override printStackTrace to print the stack trace of the encapsulated exception.
Re: How can I throw an Exception of another type from...
Posted By:
Anonymous
Posted On:
Friday, February 16, 2001 07:22 AM
Just append the first exception's description after the second exception's description in the second exception's contructor:
for Example:
try {
throw new firstException("message");
}catch(firstException fe)
throw new secondException("message;"+fe.toString());
Re: How can I throw an Exception of another type from...
Posted By:
Ravi_Van
Posted On:
Wednesday, February 14, 2001 02:45 PM
This is one way of doing it. Folks, any better solutions?
-Ravi.
try{
}catch(MyException e){
throw new MyNewException(e.toString());
}
Re: How can I throw an Exception of another type from...
Posted By:
Joe_Morse
Posted On:
Friday, February 9, 2001 10:46 AM
One clarification: your intent is to catch one type of exception, then throw another type of exception? If so, the implementation is fairly straightforward:
try {
...
} catch( BadException e ) {
throw new SpecialException( e.getMessage() );
}
Be sure your method is declared to throw your SpecialException (whatever it may be). You may also want to do a printStackTrace() on the original exception, just to indicate that it originated in your try block.