private void Main(object sender, StartupEventArgs e)
{
//全局异常
AppDomain.CurrentDomain.UnhandledException+=
ExceptionHandle.CurrentDomainUnhandledException;
Current.DispatcherUnhandledException +=
ExceptionHandle.DispatcherUnhandledException;
}
/// <summary>
/// 异常处理
/// </summary>
public class ExceptionHandle
{
#region 全局异常处理
/// <summary>
/// 异常处理
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public static void CurrentDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Exception exceptionObject = e.ExceptionObject as Exception;
if (exceptionObject != null)
{
//AppLog.AddException(exceptionObject);
}
}
/// <summary>
/// 异常处理
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public static void DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
Exception exp = e.Exception;
if (exp != null)
{
//AppLog.AddException(exp);
}
e.Handled = true;
}
#endregion
}
C# 全局异常捕捉
最新推荐文章于 2024-02-26 16:58:43 发布