던져려고 시도하는 동안 내 던져진 사용자 지정 예외를 try
/catch
으로 바꾸어야하는 이유는 무엇입니까? 그렇지만 일반적인 예외에 대해서는이를 수행 할 필요가 없습니다. 이 예에서와 마찬가지로, 내 Exception
서브 클래스 :Java에서 사용자 지정 예외 throw
public class MyException extends Exception {
public MyException(String msg) {
super(msg);
}
}
던지는 예외 : 당신이 방법을 (던져하지를하려는 경우
가public class Exe {
private static void testex(String test) {
if (null!=test) {
throw new UnsupportedAddressTypeException();
} else {//Removing try/catch block results in compile failure
try {
throw new MyException("message");
} catch (MyException e) {
e.printStackTrace();
}
}
}
}
Java 자습서의 [검사되지 않은 예외] (http://docs.oracle.com/javase/tutorial/essential/exceptions/runtime.html)를 참조하십시오. – McDowell