oh thank god, I thought I was the only one who's brain went to those weird places in normal daily life after long coding/debugging sessions! +5
Sean Sterling
Posts
-
Dreaming of the code you debug... -
Catch an Exception... then throw it?I'd also like to point out that of all the post I read in this thread, the parent to this post is the only one that was actually rethrowing the exception. Everyone else was repackaging the exception then throwing the repackaged exception which usually has the unintended consequence of losing the stack on the throw. Using the method the parent used ("throw" without a exception type reference) rethrows the last exception, full stack spool and all. i.e. Good:
try
{
// code that may throw exception here
}
catch(Exception ex)
{
// error logging here
// re-throw the exception, the stack stays safe.
throw;
}Bad:
try
{
// code that may throw exception here
}
catch(Exception ex)
{
// error logging here
// re-package the exception then throw it
// probably losing the stack along the way
throw ex;
}