java异常和线程.docVIP

  • 2
  • 0
  • 约9.74千字
  • 约 11页
  • 2016-12-29 发布于重庆
  • 举报
第九部分 异常处理和断言 几种运行时的异常 1.空指针异常 NullpointerException , 即调用不存在的对象或者没有初始化的对象 2.超出排序发范围的异常indexOutOfBoundsException , 包括:ArrayOutOfBoundsException和StringOutOfBoundsException 3.错误类型转换异常ClassCastException异常 4.数学运算异常 ArithmeticException 异常 二.异常处理方法 1.try ..catch 语句捕获 例子: public class Test1 { public static void main(String args[]){ Test1 t = new Test1(); t.divide(0); } void divide(int i){ int y = 10 ; try{ System.out.println(y + / + i + =); int a = y/i; System.out.print(a); }catch(ArithmeticException e){ System.out.println(捕获ArithmeticException); System.out.println(e.get

文档评论(0)

1亿VIP精品文档

相关文档