JAVA 自定義異常
語(yǔ)法
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=