I am trying to handle all the exceptions thrown from a async method, but when i throw the exception after the execution of an async child method,then on re-throw exception from fody(OnException method) application breaks.
Like:
using MethodBoundaryAspect.Fody.Attributes;
public sealed class ExceptionHandlerAttribute : OnMethodBoundaryAspect
{
public override void OnException(MethodExecutionArgs args)
{
//re-throw exception
throw args.Exception;
}
}
public class ClassName
{
[ExceptionHandler]
public async Task<T> MethodAsync()
{
//do some async work
await OtherClass.DoSomeWorkAsync();
throw new Exception("Exception after the execution of an Async method");
}
}
public class ParentClass
{
public async Task<T> MethodAsync()
{
try
{
ClassName className=new ClassName();
await className.MethodAsync();
}
catch(Exception ex)
{
}
}
}
OnException
should re-throw?