异常(Exception):程序的不正常现象 错误:逻辑问题 Throwable(可抛的) Exception Error 运行时异常(RuntimeException) 编译时异常 常见异常: ArithmeticException:数学运算异常 ArrayIndexOutOfBoundsException:数组下标越界异常 NullPointerException:对象为null,但是用null对象调用方法或属性 500 NumberFormatException:字符串转数字,但字符串不是纯数字 StackOverflowError:栈溢出错误,虚拟机栈运行 处理异常:try...catch()...finally catch()和finally 必须有一个 try{ //可能出现异常的代码 }[catch(捕获异常类){ //偷偷的把错误写到日志中 }]...[finally{ //总是执行 }] final:常量 finalize():析构函数 finally:总是执行 Throw Throws:方法后用s 自定义异常 多个catch:异常之间有继承 子类在前,父类在后;同级随意 基本数据类型对应的包装类: int-Integer char-Character byte-Byte short-Short long-Long float-Float double-Double boolean-Boolean 自动装箱: Integer a = 2; 自动拆箱: int b = a;
异常知识点
最新推荐文章于 2024-07-15 22:27:18 发布