In the case of synchronous code, all exceptions are propagated to the top of the stack until they are handled by a try-catch block or they are thrown as an unhandled exception. When we await on any asynchronous method, the call stack will not be the same, as the thread has made a transition from the method to the thread pool, and is now coming back. C#, however, has made it easier for us to do exception handling by changing the exception behavior for async methods. All async methods return either Task or void. Let's try to understand both scenarios with examples, and see how the programs will behave.
Exception handling with async code
A method that returns Task and throws an exception
Let's say we have the following...