Skip to main content

Exception stack trace lost

2 replies [Last post]
ygmarchi
Offline
Joined: 2003-06-10

Hi,

now in java the stack trace of a Throwable is filled when the Throwable is thrown.

If you must catch the exception for transparently doing some work, you would like to rethrow the exception without loosing the stack trace and also you may want not to change the type of the exception to make the catching code transparent to your client code.

But at the moment these two forces oppose each other since if you want to precerve the stack you must wrap the caught throwable with a new throwable, loosing the original type, which goes against the type oriented philosophy of java exception managament.

Carlo.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
forax
Offline
Joined: 2004-10-07

> Hi,

hi, i think you are in the wrong forum
but i can answer to your question.

>
> now in java the stack trace of a Throwable is filled
> when the Throwable is thrown.

no, stack trace is fill during creation of the
throwable by calling fillInStackTrace().

>
> If you must catch the exception for transparently
> doing some work, you would like to rethrow the
> exception without loosing the stack trace and also
> you may want not to change the type of the exception
> to make the catching code transparent to your client
> code.
>
> But at the moment these two forces oppose each other
> since if you want to precerve the stack you must wrap
> the caught throwable with a new throwable, loosing
> the original type, which goes against the type
> oriented philosophy of java exception managament.

you can collect the stack trace with
getStackTrace() and re-inject it in a new
exception with setStackTrace().

>
> Carlo.

Rémi Forax

ygmarchi
Offline
Joined: 2003-06-10

You're right. I'm surprised I've always been wrong all this time!

>
> no, stack trace is fill during creation of the
> throwable by calling fillInStackTrace().
>
> >
> > If you must catch the exception for transparently
> > doing some work, you would like to rethrow the
> > exception without loosing the stack trace and also
> > you may want not to change the type of the
> exception
> > to make the catching code transparent to your
> client
> > code.
> >
> > But at the moment these two forces oppose each
> other
> > since if you want to precerve the stack you must
> wrap
> > the caught throwable with a new throwable, loosing
> > the original type, which goes against the type
> > oriented philosophy of java exception managament.
>
> you can collect the stack trace with
> getStackTrace() and re-inject it in a new
> exception with setStackTrace().
>
> >
> > Carlo.
>
> Rémi Forax