Java 异常

Java 异常

Throwable 异常超类

  • Exception
  • Error

1、异常关键字

try、catch、finally、throw、throws

try{
    System.out.println(11/0);
}catch (ArithmeticException e){
    System.out.println("出现异常!");
}finally {
    System.out.println("finally");
}

快捷键 : Ctr l+ Alt + T

2、自定义异常

继承 Exception 类

public class GendorException extends Exception {
    public GendorException(String msg)
    {
        super(msg);
    }
}
原文地址:https://www.cnblogs.com/gbhh/p/13780977.html