java异常回顾

String getMessage():返回此Throwable的详细消息字符串

void PrintStackTrace():将throw及其追踪输出至标准错误流

void printStackTrace(PrintStream s):将此throwable及其追踪输出到指定的输出流

package abnormal;

public class Demo {
    public static void main(String[] args) {
        try{
            int result = divide(4, 0);
            System.out.println(result);
        }catch(Exception e){
            System.out.println("捕获的异常息为" +e.getMessage());
        }finally{
            System.out.println("进入finally");
        }
        System.out.println("程序继续往下执行");
    }
    
    public static int divide(int x, int y){
        return x / y;
    }
    
}
原文地址:https://www.cnblogs.com/rain-1/p/5268127.html