JAVA 笔记[11.1][JAVA 异常--自定义异常]

JAVA 自定义异常

语法

MyException.java

public class MyException extends Exception{
    public MyException(String msg){
        super(msg);
    }
}

EnterMyException.java

public class EnterMyException{
    public static void main(String[] args){
        try{
            throw new MyException("=test exception=");
        }catch(MyException e){
            System.out.println(e.getMessage());
        }
    }
}

输出

=test exception=

你可能感兴趣的:(JAVA 笔记[11.1][JAVA 异常--自定义异常])