有人知道是否可以将下面的catch块中的代码编写为单个语句?我无法想出办法,如果有的话,我只是很好奇.
重要信息:必须保留堆栈跟踪.
catch (Exception e)
{
if (e is MyCustomException)
{
// throw original exception
throw;
}
// create custom exception
MyCustomException e2 =
new MyCustomException(
"An error occurred performing the calculation.", e);
throw e2;
}
Run Code Online (Sandbox Code Playgroud)
Mat*_*ias 15
关于什么:
catch (MyCustomException)
{
throw;
}
catch (Exception ex)
{
throw new MyCustomException(ex);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1407 次 |
| 最近记录: |