이 코드를 고려메인에서 예외가 발생하면 어떻게됩니까?
public class Test {
public static void main(String[] args) throws Exception {
mayFail();
System.out.println("This shouldn't run");
}
public static void mayFail() throws Exception{
throw new Exception();
}
}
은 내가 Exception
가 throw
앤 경우 main
이 종료됩니다 알고있다.
제가 알고 싶은 것은 JVM
(또는 어느 곳에서나) 이런 일이 발생할 때 실행되는 왕이 있습니까?
편집 : 나는 제대로이 아니라 멀리는 간다 이해한다면
public class Test{
public static void main(String[] args) throws Exception {
UncaughtExceptionHandler a = new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
System.out.println("Uncaught Exception");
}
};
Thread.setDefaultUncaughtExceptionHandler(a);
mayFail();
System.out.println("This shouldn't run");
}
public static void mayFail() throws Exception{
throw new Exception();
}
}
:
마스를 읽은 후 내가 너무 좋아이 Exception
을 처리하기 위해 관리 대답 샤이 크? 그리고 UncaughtExceptionHandler
없이 프로그램은 아무 것도하지 않고 종료됩니다.
@Charlie 당신은 내 질문을 이해하지 못했습니다. –
그래서 내 코멘트를 삭제했습니다 : I – Charlie