c# - 重新抛出异常 Fody 时应用程序中断
问题描述
我正在尝试处理从异步方法抛出的所有异常,但是当我在执行异步子方法后抛出异常时,然后从 fody(OnException 方法)应用程序中断重新抛出异常。
喜欢:
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)
{
}
}
}
解决方案
推荐阅读
- json - 处理 ELK 堆栈中的任意 JSON 日志
- python-3.x - 检查和计算给定子字符串是否存在于 Python 中的字符串中的有效方法
- python - 如何在 selenium Webdriver for python 中按索引查找元素
- javascript - 收到新消息时如何播放声音(聊天系统)
- python - Pymysql 1064,“您的 SQL 语法有错误
- node.js - socket.io 中的多个或后续 Volatile 发射
- javascript - 当单击的元素在同一选项卡上为表单执行 POST 时,OnClick 在 iOS 上不起作用
- xml - 解析多状态响应的性能不佳
- dns - 有没有办法从 dns 获取 ip 地址/域名?
- python-3.x - 使用 MongoEngine 连接池