package pkg7.pkg15;
//自訂例外的類別
class MyException extends Exception{
public MyException(String msg){
super(msg);
}
}
public class Main {
public static void main(String[] args) {
int a = 10;
try{
if(a == 10){
throw new MyException("自訂的例外。");
}
}catch(Exception e){
System.out.println(e);
}
}
}
pkg7.pkg15.MyException: 自訂的例外。
全站熱搜
留言列表