java常见异常汇总

java.lang.ArithmeticException
算术运算异常,因为除数为0,所以引发了算数异常

java.lang.StringIndexOutOfBoundsException: String index out of range: -1
这是截取字符串substring()产生的下标越界异常。原因是可能是字符串为空,或长度不足
1

ClientAbortException: java.io.IOException异常
原因是由于服务器正在处理http请求,正在输出内容时,用户关闭了浏览器,造成了ClientAbortException异常。它属于I/O异常中比较常见的一种。

ClientAbortException  Caused by: java.net.SocketException: Connection reset by peer: socket write error
这种异常已比较常见,通常有以下几种情况:
服务器的并发连接数超过了其承载量,服务器会将其中一些连接Down掉;客户关掉了浏览器,而服务器还在给客户端发送数据

java.lang.NullPointerException
空指针异常 出现该异常的原因在于某个引用为null,但却调用了它的某个方法,这时就会出现该异常

ClassCastException
类型强制转换异常,例如:Object x = new Integer(0);System.out.println((String)x);

IllegalArgumentException
传递非法参数异常,此异常表明向方法传递了一个不合法或不正确的参数。你看看传值的方法是否参数不正确

ArrayStoreException
向数组中存放与声明类型不兼容对象异常,
例如:Object x[] = new String[3];x[0] = new Integer(0);

NegativeArraySizeException
创建一个大小为负数的数组错误异常,例如int[] arr = new int[10];int i = arr[-1];

NumberFormatException
数字格式异常,例如:把"176//240"这个输入字条转换为一个数字

SecurityException
安全异常,例如:android的权限异常,运行java的程序提示Missing requitedPermissions manifest attribute in main jar等

UnsupportedOperationException
不支持的操作异常,例如
String testStr = "100,300,400,545,666";
List test = Arrays.asList(testStr.split(","));
test.remove("100");
        使用Arrays.asList()方法一定要注意类型的转换。

Java中的异常分为两大类:

  1.Checked Exception(非Runtime Exception)

  2.Unchecked Exception(Runtime Exception)运行时异常

  RuntimeException类是Exception类的子类,它叫做运行时异常,Java中的所有运行时异常都会直接或者间接地继承自RuntimeException类。

  Java中凡是继承自Exception,而不继承自RuntimeException类的异常都是非运行时异常。



你可能感兴趣的:(java常见异常汇总)