Await in catch/finally - C# 6 Language New features

If your system encounters any exception, it will throw exception and show Yellow Screen of Death and the system will stop at that screen. So what we have to handle exceptions?

Try catch is best practice to handle exceptions. Try-catch statement have one try block followed by one or more catch block. When an exception occurs CLR will look up for an appropriate catch block to handle exceptions.

Microsoft is continually improving Exception Handling techniques. This time Microsoft Introduce another new feature for C# 6 Await in Catch/finally. which is very useful to developers who are using asynchronous calls.

Since C# 6 released we can't use a wait in a catch or finally block in till C# 6 released. The compiler doesn't have any way to go back in a catch block to execute what is after your await instruction or something like that... Now, No need to write any custom tweaks to implement await in try-catch.

In previous version you have to achieve await in catch/finally by following code

You can move the logic outside of the catch block and re-throw the exception after, if needed, by using ExceptionDispatchInfo. (solution link)
C# 6 make thing easier, you don't have to capture and re-throw exception again.

In the example, I implemented the simple async-await logic. Try block will throw exception and after catching exception I delay task for 10 Second. which mean application is currently in kind of sleeping state. After waiting time completed exception will print on the console.Output