I have a base framework designed to deal with errors generically; however, when the error occurs, I appear to not be catching it in my framework. The following code is a simplified version of what I'm trying to achieve:
class Program
{
static void Main(string[] args)
{
RunMethod<decimal>(() =>
{
decimal x = 0;
decimal y = 1 / x;
return y;
});
}
private static async Task<T> RunMethod<T>(Func<T> method)
{
try
{
var result = await TryRunningMehod<T>(method);
return result;
}
catch (DivideByZeroException ex)
{
System.Diagnostics.Debug.WriteLine("Error");
return default(T);
}
}
private static async Task<T> TryRunningMehod<T>(Func<T> method)
{
var returnValue = await Task.Run<T>(method);
return returnValue;
}
}
What happens when you run the above code is it crashes on the divide by zero. I'm trying to make it write a debug message and continue.
I have break on unhandled exceptions only flagged.
My exceptions settings:
What the IDE looks like when it breaks: