I'm having some trouble with an exception I am getting from some async code. I don't want to block my thread while the
private async Task ThrowSomeExceptionAsync()
{
//Some long running process would go here...
throw new Exception();
}
This is the method I want to call, and to catch the exception. I am using the Application.UnhandledException event to catch my exceptions, but in this case it's not being caught.
I tried waiting for the Exception property on the returned Task object to be populated, but that blocks while the task is being completed.
Using the ContinueWith method prevented blocking, but any exceptions thrown from the delegate weren't caught by the UndhandledException event.
How can I execute this code in an async fashion, yet still use my UnhandledException event for error handling? Am I missing some fundamental concept about that event?