我可以在运行时在方法Helper()中检测到程序执行是抛出异常的结果吗?
注意,我的目标是避免扩展方法Helper()将异常对象作为输入参数.
public void MyFunc1()
{
try
{
// some code here that eventaully throws an exception
}
catch( Exception ex )
{
Helper();
}
}
public void MyFunc2()
{
Helper();
}
private void Helper()
{
// how can I check if program execution is the
// result of a thrown exception here.
}
Run Code Online (Sandbox Code Playgroud)
有涉及一个可怕的黑客Marshal.GetExceptionPointers和Marshal.GetExceptionCode不放在这里所有的平台是工作:
public static Boolean IsInException()
{
return Marshal.GetExceptionPointers() != IntPtr.Zero ||
Marshal.GetExceptionCode() != 0;
}
Run Code Online (Sandbox Code Playgroud)
从这个页面:http://www.codewrecks.com/blog/index.php/2008/07/25/detecting-if-finally-block-is-executing-for-an-manhandled-exception/
| 归档时间: |
|
| 查看次数: |
1357 次 |
| 最近记录: |