This is something that I’ve known for a while, but always seem to forget when it comes to actually implementing it in my code.
When catching an exception, most people catch it as a variable, such as “ex” and then just do a “throw ex” and throw that exception back up the chain. This is probably not what you want. When the stack trace/error information comes back from that exception, it will show as having occurred where your “throw ex” was. This isn’t really helpful if your “try” block contains a lot of code.
Instead, you should just simply write “throw”, without passing a specific exception. This allows the stack trace to show the original location of the error (instead of where you caught the exception and threw it again.) This information is much more helpful when debugging..
And now you know too!
Remember Me
a@href@title, b, blockquote@cite, em, i, strike, strong, sub, sup, u