Java——异常(try...catch...finally)

public class Demo5_Throwable {
    public static void main(String[] args) {
        try{
            System.out.println(1/0);
        }catch(Exception e){
            System.out.println(e.getMessage());//获取异常信息,返回字符串;
            System.out.println(e.toString());//获取异常类名和异常信息,返回字符串;
            System.out.println(e);//调用toString方法,打印异常类名和异常信息;
            e.printStackTrace();//jvm默认就用这种方式处理异常:获取异常类名和异常信息,以及异常出现在程序中的位置。返回值void。
        }
    }
}

猜你喜欢

转载自blog.csdn.net/qq_41264055/article/details/81045312