62,616
社区成员
发帖
与我相关
我的任务
分享
class Demo {
int i = 0;
/*
public void test() throws MyException{
try{
System.out.println(1 / 0);
}catch(Exception me){
throw new MyException("出现了自定义异常");
}
}
*/
}
public void test() throws MyException{
System.out.println(1 / 0);
}
public class Demo01 {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Demo demo = new Demo();
try{
demo.test();
}catch(MyException me){
System.out.println(me.getMessage());
System.out.println("捕捉自定义异常成功");
}
}
}
class Demo {
int i = 0;
public void test() throws MyException{
try{
System.out.println(1 / 0);
}catch(Exception me){
throw new MyException("出现了自定义异常");
}
}
}
// 定义异常类
class MyException extends Exception {
public MyException(String mesg) {
super(mesg);
}
}