I am using a third party DLL which offers an async method to perform an operation.
I run this inside a try-catch block but - with JustMyCode disabled - I get an error originating from somewhere inside the third party object which can only be handled in AppDomain.CurrentDomain.UnhandledException, which closes the app and is far to generalised as a place to handle this.
The code:
try { ResultObject result = await thirdPartyObject.MethodAsync(); }
catch { /* never get here */ }
The signature of the thirdPartyObject.MethodAsync() from reflection:
public Task<ResultObject> MethodAsync();
After hitting the internal error (which is only visible with 'Just My Code' disabled in VS settings), it goes onto a System.Threading.Tasks.TaskCanceledException: 'A task was canceled.' ...
Is there a way to intercept that task cancellation without hitting the global unhandled exception handler?
thirdPartyObject.MethodAsync().Result;will do?