프로젝트에 대해 해결할 수없는 문제가 있습니다.무한 루프의 처리되지 않은 예외
namespace TestApp
{
class Program
{
static void Main(string[] args)
{
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionsHandler);
int[] a = { 0, 1, 2 };
int y = a[6];
}
public static void UnhandledExceptionsHandler(object sender, UnhandledExceptionEventArgs e)
{
try
{
File.AppendAllText("Exceptions.log", (e.ExceptionObject as Exception).Message);
}
catch (Exception ex)
{
Environment.Exit(1);
}
}
}
}
처리되지 않은 예외 처리기는 실제로 처리되지 않은 예외를 원하는대로 잡고 로그 파일에 메시지를 작성합니다. 그러나 핸들러를 종료하면 코드가 범위를 벗어나는 인덱스와 함께 다시 시작됩니다. int y = a [6]. 다음 코드 줄로 이동하거나 처리되지 않은 예외 (일반적으로이 경우 앱 종료)로 진행하려면 코드가 필요합니다. 그것이 그대로, 처리되지 않은 예외를 throw하는 무한 루프에 처리됩니다/처리되지 않은 예외 이벤트 처리기를 누르십시오. 핸들러에서
'try/catch' 대신'try/finally'를 사용 하시겠습니까? – Jon