对异常类的理解(程序输出)
public class Test{
public static void main(String[] args) {
String test = "yes";//no
try{
System.out.println("start try");
doRisky(test);//若在此处抛出异常,后面的一句不执行
System.out.println("end try");
}
catch(ScaryException se){
System.out.println("scary exception");
}
finally{
System.out.println("finally");
}
System.out.println("end of main");
}
static void doRisky(String test) throws ScaryException{
System.out.println("start risky");
if("yes".equals(test)){
throw new ScaryException();//若在此处抛出异常,后面的一句不执行
}
System.out.println("end risky,在test是no的时候会输出,在test是yes的时候不会输出,");
}
}
class ScaryException extends Exception{
}
//Answer:
//start try
//start risky
// end risky
// end risky
//finally
//end of main
//start try
//start risky
//scary exception
//finally
//end of main
本文来自博客园,作者:{李浩正},转载请注明原文链接:https://www.cnblogs.com/hzzzz/p/16290323.html