ASP.NET에서 처리되지 않은 오류를 처리하기 위해 global.asax 내에 Application_Error
을 사용할 수 있습니다.Windows Forms 프로젝트에 대한 중앙 오류 처리기 배치 위치
Windows 양식에 해당하는 항목이 있습니까?
ASP.NET에서 처리되지 않은 오류를 처리하기 위해 global.asax 내에 Application_Error
을 사용할 수 있습니다.Windows Forms 프로젝트에 대한 중앙 오류 처리기 배치 위치
Windows 양식에 해당하는 항목이 있습니까?
예 그것은 당신의 응용 프로그램의 아키텍처에 따라
using System;
using System.Security.Permissions;
public class Test {
[SecurityPermission(SecurityAction.Demand, Flags=SecurityPermissionFlag.ControlAppDomain)]
public static void Example()
{
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler);
try {
throw new Exception("1");
} catch (Exception e) {
Console.WriteLine("Catch clause caught : " + e.Message);
}
throw new Exception("2");
// Output:
// Catch clause caught : 1
// MyHandler caught : 2
}
static void MyHandler(object sender, UnhandledExceptionEventArgs args) {
Exception e = (Exception) args.ExceptionObject;
Console.WriteLine("MyHandler caught : " + e.Message);
}
public static void Main() {
Example();
}
}
[STAThread]
static void Main()
{
Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
Application.Run(new FrmMain());
}
private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
{
MessageBox.Show("Unhandled exception: "+e.Exception.ToString());
}
의 AppDomain.UnhandledException. 예를 들어, MVC 아키텍처를 수행하면 책임 패턴 패턴 [GOF]을 알고 있거나 모든 유형의 실행 파일을 처리하는 것을 선호한다면 controler.if 파일에 있어야합니다. 그렇지 않으면 앱에 대해 자세히 알려주세요.
응용 프로그램에 여러 AppDomains가있는 경우 해당 이벤트를 각각에 연결해야합니다. –