日期:2014-05-20 浏览次数:20727 次
public class Worker {//定义Worker类
public static void main(String[] args) {
try{
new Car().run();
}catch(CarWrongException e){
System.out.println(e.getMsg());
System.out.println("异常处理结束");
}
}
}
class CarWrongException extends Exception{ //定义CarWrongException类
private String msg;
public CarWrongException(String msg){
this.msg = msg;
}
public String getMsg(){
return msg;
}
}
class Car{//定义Car类
public void run() throws CarWrongException{
throw new CarWrongException("CarWrongException !");
}
}