现在的位置: 首页 > 综合 > 正文

Java笔记之常见异常

2013年10月12日 ⁄ 综合 ⁄ 共 891字 ⁄ 字号 评论关闭

常见的运行时异常如下:

(1) 类型转换异常 ClassCastException  

String strName=new 
string(“123”);
int nNumber=(int)strName;

(2) 数组超界异常

ArrayIndexOutBoundsException

int[] b=new int[10];

b[10]=1000;     

(3) 指定数组维数为负值异常

NegativeArraySizeException

b[-1]=1001;

(4) 算术异常ArithmeticException 

int b=0;
a=500/b; 

(5) Java系统内部异常InternalException JVM抛出的异常。

(6) 类型不符合异常IncompatibleTypeException 

	int n=12345; 
 	String s=(String)n; 

(7) 内存溢出异常OutOfMemeoryException 

(8) 没有找到类定义异常 

NoClassDefFoundException 
aClass aa=new aClas(); //但aClass类未定义。

(9) 空指针异常NullPointerException 

	 int b[ ]; 
	 b[0]=99;   //没有实例化,就访问,将产生空指 针。 

常见的非运行时异常如下: 

(1) ClassNotFoundException :找不到类或接口所产生的异常 
(2) CloneNotSupportedException:使用对象的clone 方法但无法执行Cloneable 所产生的异常。 
(3) IllegalAccessException :类定义不明确所产生的异常。例如:类不为public , 或是包含一个类定义在另一个类库内。 
(4) IOException :在一般情况下不能完成I/O操作所产生的异常。 
(5) EOFException: 打开文件没有数据可以读取所产生的异常 
(6) FileNotFoundException :在文件系统中,找不到文件名称或路径所产生 
(7) InterruptedIOException: 目前线程等待执行,另一线程中断目前线程I/O运行所产生的异常 

【上篇】
【下篇】

抱歉!评论已关闭.