다음 코드에 대해 처리되지 않은 예외 유형 오류가 발생합니다. 이해하지만 catch 블록에서 예외를 처리했습니다.처리되지 않은 예외 오류가 catch 블록을 잡는 중임을 나타냅니다.
class NewException extends Exception{
private String msg;
public NewException(String msg){
this.msg = msg;
}
public String getExceptionMsg(){
return msg;
}}
class CatchException {
public static void method() throws NewException{
try {
throw new NewException("New exception thrown");
}
catch (NewException e){
e.printStackTrace();
System.out.println(e.getExceptionMsg());
}
finally {
System.out.println("In finally");
}
}}
public class TestExceptions{
public static void main(String[] args){
CatchException.method();
}}
ex 네가 말하는 것처럼 너는 그것을 얻지 못한다. – Cratylus
@Cratylus에 동의하지만,'e.printStackTrace()'를 실행하면 IDE/명령 행 도구에서 예외가 발생한 것처럼 보일 것입니다. –
@ Cratylus, @ FlorianMinges : 나는 내가 이해하고 있는지 확신하지 못한다. Thinking in Java의 예제와 다른 점은 무엇입니까? http://www.linuxtopia.org/online_books/programming_books/thinking_in_java/TIJ311_005.htm? – Jin