Exception 子类的继承关系 Exception ClassNotFoundException ClassNotSupportedException essException InstantiationException InterruptedException NoSuchMethodException RuntimeException ArithmeticException ArrayStoreException ClassCastException IllegalArgumentException 1 Exception 子类(续) IllegalThreadStateException NumberFormatException IllegalMonitorStateException IndexOutOfBoundsException ArrayIndexOutOfBoundsException StringIndexOutOfBoundsException NegativeArraySizeException NullPointerException SecurityException 2 13周-上机作业 1 ?设计一个 java 程序,有数组 a()={10 , 20, 30, 40, 50};b()={0,2,30}; 求数组 c()=a[i]/b[i],i=0-4. 请处理此程序所发生的任何异常( ArrayIndexOutofBoundsException ) ( ArithemeticException ) 3 ?1关于异常的含义,下列描述正确的是?A程序编译错误? B 程序语法错误? C 程序自定义的异常?D程序编译或者运行时发生的异常事件 D 4 ? 5 对于 try 和 catch 子句的排列方式,下列哪一项是正确的? ?A子类异常在前,父类异常在后? B 父类异常在前,子类异常在后? C 只能有子类异常? D 父类异常和子类异常不能同时出现在同一个类中 A 5 ? 7 关于 java 语言中常用的异常类的说法,错误的一个是?A在不合法的数学运算发生时,会出现 ArithmeticException 类异常?B如果字符串转换成数字,需要准备处理 NumberFormatException 异常?C如果使用非法的索引值来访问数组, ArrayIndexOutOfBoundsException 异常会被抛出?D如果指针变量为空, NullPointException 异常就会被抛出 D Java 中没有指针使用 null 对象引用方法或变量将产生该异常 6 ? 14 运行下列程序,将产生什么异常? ? A ArrayIndexOutOfBoundsException ? B NumberFormatException ? C ArithmeticException ? D ArithmeticException 和 ArrayIndexOutOfBoundsException public class test14 { public static void main(String[] args) { int x=0; int y=2/x; int z[]={1,2,4,6}; int p=z[4]; }}C 7抛出异常语句通常情况下,异常是由系统自动捕获的。但程序员也可以自己通过 throw 语句抛出异常。 throw 语句的格式为: throw new 异常类名(信息) 其中异常类名为系统异常类名或用户自定义的异常类名, “信息”是可选信息。如果提供了该信息, toString() 方法的返回值中将增加该信息内容。 8 public class Deposit { public static double discount( int n) { if (n<0){ throw new IllegalArgumentException( "n应该为正整数");} return n*; }public static void main(String args[]){ try {int i=Integer. parseInt (args[0]); System. out .println( "用户消费"+i+ "元,可优惠"+discount (i)+ "元"); }catch (ArrayIndexOutOfBoundsException e1){ System. out .println( "异常:没有输入参数"); }catch (NumberFormatException e2){ System. out .pri
java速成课件异常2 来自淘豆网m.daumloan.com转载请标明出处.