Nick Weinholt (.Net Performance guru and MVP) has an article on the
correct
method for rethrowing an exception in C# so that the Exception.StackTrace
actually points to the root problem.
In C# the correct method for rethowing an exception is using throw;
without any arguments within the catch block:
try {
// code
}
catch (Exception ex) {
throw; // Rethrow exception without
resetting StackTrace
}
// code
}
catch (Exception ex) {
throw; // Rethrow exception without
resetting StackTrace
}
In VB.Net the method is the same:
Try
‘ code
‘ code
Catch ex As
Exception
Throw
‘ Rethrow exception without resetting StackTrace
End Try
Using this method the stack trace will go all the way down to the original
exception, and not just to your catch block.