处理 InnerException 最佳方案?


如何获取 innerException 内部错误信息

String innerMessage = (ex.InnerException != null) 
                      ? ex.InnerException.Message
                      : "";

这断代码看上去可以解决问题,但是党innerException中还有innerException的得时候就无效了。

所以有了下面得扩展方法,使用递归获取innerException,完美解决

public static class ExceptionExtensions
{
    public static Exception GetOriginalException(this Exception ex)
    {
        if (ex.InnerException == null) return ex;

        return ex.InnerException.GetOriginalException();
    }
}

参考:http://stackoverflow.com/questions/1456563/best-way-to-check-for-inner-exception


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM