C#使用反射来捕获异常抛出

cod*_*deg 1 c# asp.net error-handling

有没有办法在catch块中使用反射或其他方法来获取抛出的异常类型,以及堆栈跟踪而不附加catch(Exception ex)参数?

我想要一种方法来捕获所有异常并减轻代码分析的发现,以获得过于广泛的捕获.

catch
{
     //Include Reflection here to get error thrown information

     divRecordNotFound.Visible = true;
     labelRecordNotFound.Text = string.Format(System.Globalization.CultureInfo.CurrentCulture, "{0}{1}", ValidNS.Properties.Resoures.ErrorValue); 
     divRecordFound.Visible = false;
}
Run Code Online (Sandbox Code Playgroud)

J. *_*ond 5

通过执行a,catch (Exception ex)您还可以捕获所有派生自的异常Exception.如果你想要它的类型,你可以打电话ex.GetType().希望它有所帮助;)