T
Tony Johansson
Hi!
I'm reading the e-learning from Microsoft and there is one thing that I hope
somebody can answer.
In the Best practice section below it says that if I rethrow an existing
exception the stack trace is maintained.
But if I read the description section below I get the impression that the
origination stack trace is removed.
....
So my question is if I rethrow an existing exception in the catch part like
this
catch(Exception e)
{
throw e;
}
will the stack trace be maintained from where the origination place where
the exception occured ?
Best practice
Use the throw keyword without specifying an exception to rethrow an
exception while maintaining the stack trace.
Description
The runtime generates and maintains a stack trace from the point at which an
exception is thrown. If you rethrow the exception, the stack trace is
cleared and the originating point of the exception is lost. When you need to
rethrow an exception without wrapping it in another exception, the correct
syntax is to use the throw keyword without specifying an exception. The
original exception will propagate up with its stack trace intact.
//Tony
I'm reading the e-learning from Microsoft and there is one thing that I hope
somebody can answer.
In the Best practice section below it says that if I rethrow an existing
exception the stack trace is maintained.
But if I read the description section below I get the impression that the
origination stack trace is removed.
....
So my question is if I rethrow an existing exception in the catch part like
this
catch(Exception e)
{
throw e;
}
will the stack trace be maintained from where the origination place where
the exception occured ?
Best practice
Use the throw keyword without specifying an exception to rethrow an
exception while maintaining the stack trace.
Description
The runtime generates and maintains a stack trace from the point at which an
exception is thrown. If you rethrow the exception, the stack trace is
cleared and the originating point of the exception is lost. When you need to
rethrow an exception without wrapping it in another exception, the correct
syntax is to use the throw keyword without specifying an exception. The
original exception will propagate up with its stack trace intact.
//Tony