这篇文章就是个笔记,大家可以直接不看。
public class catchline {
public static void main(String[] args){
catchline ct=new catchline();
try{
ct.test2();
}catch(Exception e){
e.printStackTrace();
}
}
public void test1() throws DrinkException{
throw new DrinkException("喝车别开酒");
}
public void test2(){
try{
test1();
}catch(Exception e){//注意这里必须是Exception e不能只是DrinkException e。那不完善,一般的做法都是在这里抛出一个普通的大类异常,Exception
RuntimeException newExc=new RuntimeException("司机一滴酒,亲人两行泪~~");
newExc.initCause(e);
throw newExc;
}
}
}
class DrinkException extends Exception {
private static final long serialVersionUID = 1L;
public DrinkException(String message){
super(message);
}
public DrinkException(){
}
}