10.5 Throwable类

来源:互联网 发布:cnc串联程序软件 编辑:程序博客网 时间:2024/05/16 17:30

Throwable为super类下面子类有error和Exception两个大类。

Exception包含:运行异常和编译异常。

异常:异常体系:-----------|Throwable------------------|Error------------------|ExceptionThrowable常用的方法:toString()  返回当前异常对象的完整类名+错误信息  StringgetMessage() 返回的是创建Throwable传入的字符串信息 StringprintStackTrace() 打印异常栈信息 void 

class ThrowableErrorEecption{public static void main(String[] args) {/*Throwable t = new Throwable("头晕"); System.out.println("toString() 方法返回值"+t.toString());//java.lang.Throwable  返回 包名+类名+错误信息System.out.println("getMessage() 方法返回值"+t.getMessage());//*/test();}public static void test(){Throwable t = new Throwable("头晕");t.printStackTrace();/*java.lang.Throwable: 头晕        at ThrowableErrorEecption.test(ThrowableErrorEecption.java:27)        at ThrowableErrorEecption.main(ThrowableErrorEecption.java:24)*/}}


0 0
原创粉丝点击