异常
异常处理机制
- 抛出异常
- 捕获异常
异常处理五个关键字
try,catch,finally,throw,throws
快捷方式:ctrl+alt+t
package com.zhang.oop.exception;
import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput;
public class Demo01 {
public static void main(String[] args) { //捕获多个异常要从小到大
try { //try监控区域
new Demo01().a();
} catch (Error e) { //catch(想要捕获的异常类型)
System.out.println("程序出现异常");
}catch(Exception e){
System.out.println("exception");
}catch(Throwable t){
System.out.println("throwable");
}finally { //处理善后工作 可以不要finally
System.out.println("finally");
}
}
public void a(){
b();
}
public void b(){
a();
}
}
标签:System,finally,catch,异常,public,out
From: https://www.cnblogs.com/rockz/p/17217538.html