While working with C# recently without having a decent experience in it, I am sometimes wondering how one or another case is working in the language.
Without having the ability to alter any production project just for the sake of science, I created this project for experimenting. Feel free to contribute or fix any issues you find valuable.
You can find the experiment details in AwaitException.Project and AwaitException.Test.
Turns out if just run an async method without await and an exception occurs in the method - it gets lost in the void.
The question is: how the stack trace is affected if we throw an exception, catch it for logging and then rethrow.
The answer:
- If the exception is rethrown explicitly via
throw exception;the stack trace is erased. - If the exception is rethrown via
throw;the stacktrace is preserved.