北京品牌高端网站建设公司,网站设计的性能需求,wordpress的插件目录,市场营销论文异常分类
Throwable
是java异常的顶级类#xff0c;所有异常都继承于这个类。 Error,Exception是异常类的两个大分类。
Error
Error是非程序异常#xff0c;即程序不能捕获的异常#xff0c;一般是编译或者系统性的错误#xff0c;如OutOfMemorry内存溢出异常等。
Exc…异常分类
Throwable
是java异常的顶级类所有异常都继承于这个类。 Error,Exception是异常类的两个大分类。
Error
Error是非程序异常即程序不能捕获的异常一般是编译或者系统性的错误如OutOfMemorry内存溢出异常等。
Exception
Exception是程序异常类由程序内部产生。Exception 又分为运行时异常非运行时异常类。
运行时异常
运行时异常的特点是java编译器不会检查它也就是说当程序中可能出现这类异常时会编译通过但是在运行时会出现错误。 如NullPointExceptionArrayIndexoutOfBuoundsException等。
非运行时异常
程序必须进行处理的异常编译不通过必须捕获或者抛出。如IOException,ClassNotFoundException等。
java常见的异常有哪些
1、NullPointerException
空指针异常操作一个 null 对象的方法或属性时会抛出这个异常。 private static void NullPointer() {String s null;System.out.println(s.equals(123));}2、OutofOutofMemoryError
内存出现异常的一种异常这不是程序能控制的是指要分配的对象的内存超出了当前最大的堆内存需要调整堆内存大小(-Xmx)以及优化程序。
3、IOException
IO即input, output我们在读写磁盘文件、网络内容的时候经常会生的一种异常这种异常是受检查异常需要进行手工捕获。 如文件读写会抛出 IOException
public int read() throws IOException
public void write(int b) throws IOException4、FileNotFoundException
文件找不到异常如果文件不存在就会抛出这种异常。 FileNotFoundException 其实是 IOException 的子类同样是受检查异常需要进行手工捕获。 如定义输入输出文件流文件不存在会报错
public FileInputStream(File file) throws FileNotFoundException
public FileOutputStream(File file) throws FileNotFoundException5、ClassNotFoundException
类找不到异常Java开发中经常遇到是不是很绝望这是在加载类的时候抛出来的即在类路径下不能加载指定的类。它是受检查异常需要进行手工捕获。
看一个示例
public static Class getExistingClass(ClassLoader classLoader, String className) {try{return (Class) Class.forName(className, true, classLoader);} catch( ClassNotFoundException e) {return null;}
}6、ClassCastException
类转换异常将一个不是该类的实例转换成这个类就会抛出这个异常。 这是运行时异常不需要手工捕获。
如将一个数字强制转换成字符串就会报这个异常
Object x new Integer(0);
System.out.println((String)x);7、IndexOutOfBoundsException
索引越界异常当操作一个字符串或者数组的时候经常遇到的异常。它是运行时异常不需要手工捕获。
例一个ArrayList数组中没有元素而你想获取第一个元素,运行是就会报此类型的错误。
public class test{public static void main(args[] ){List list new ArrayList();System.out.println(list.get(0));}
}8、ArithmeticException
算术异常发生在数字的算术运算时的异常如一个数字除以 0 就会报这个错。 double n 3 / 0;9、NumberFormatException
数字格式异常。当试图将一个String 转换为指定的数字类型而该字符串确不满足数字类型要求的格式时抛出该异常。 例如 private static void NumberFormat(){String a a;int b Integer.valueOf(a);System.out.println(b);}10、StringIndexOutOfBoundsException
字符串索引越界异常。当使用索引值访问某个字符串中的字符而该索引值小于0或大于等于序列大小时抛出该异常. //字符串索引越界异常private static void StringIndexOutOfBounds(){String a a;System.out.println(a.substring(3,4));} 文章转载自: http://www.morning.smj78.cn.gov.cn.smj78.cn http://www.morning.yhljc.cn.gov.cn.yhljc.cn http://www.morning.cjwkf.cn.gov.cn.cjwkf.cn http://www.morning.zwsgl.cn.gov.cn.zwsgl.cn http://www.morning.lynb.cn.gov.cn.lynb.cn http://www.morning.ntyks.cn.gov.cn.ntyks.cn http://www.morning.fhcwm.cn.gov.cn.fhcwm.cn http://www.morning.cpnsh.cn.gov.cn.cpnsh.cn http://www.morning.yhjrc.cn.gov.cn.yhjrc.cn http://www.morning.cnqdn.cn.gov.cn.cnqdn.cn http://www.morning.cpfbg.cn.gov.cn.cpfbg.cn http://www.morning.gthwz.cn.gov.cn.gthwz.cn http://www.morning.hqbnx.cn.gov.cn.hqbnx.cn http://www.morning.ctfh.cn.gov.cn.ctfh.cn http://www.morning.hhnhb.cn.gov.cn.hhnhb.cn http://www.morning.jbblf.cn.gov.cn.jbblf.cn http://www.morning.tftw.cn.gov.cn.tftw.cn http://www.morning.kqbjy.cn.gov.cn.kqbjy.cn http://www.morning.mplb.cn.gov.cn.mplb.cn http://www.morning.wqsjx.cn.gov.cn.wqsjx.cn http://www.morning.qwgct.cn.gov.cn.qwgct.cn http://www.morning.xkwyk.cn.gov.cn.xkwyk.cn http://www.morning.wprxm.cn.gov.cn.wprxm.cn http://www.morning.lmfxq.cn.gov.cn.lmfxq.cn http://www.morning.lznqb.cn.gov.cn.lznqb.cn http://www.morning.deupp.com.gov.cn.deupp.com http://www.morning.bqpgq.cn.gov.cn.bqpgq.cn http://www.morning.rwcw.cn.gov.cn.rwcw.cn http://www.morning.xysxj.com.gov.cn.xysxj.com http://www.morning.dnbkz.cn.gov.cn.dnbkz.cn http://www.morning.zyrcf.cn.gov.cn.zyrcf.cn http://www.morning.jzklb.cn.gov.cn.jzklb.cn http://www.morning.nffwl.cn.gov.cn.nffwl.cn http://www.morning.rksnk.cn.gov.cn.rksnk.cn http://www.morning.ydxwj.cn.gov.cn.ydxwj.cn http://www.morning.glcgy.cn.gov.cn.glcgy.cn http://www.morning.fldk.cn.gov.cn.fldk.cn http://www.morning.ghzfx.cn.gov.cn.ghzfx.cn http://www.morning.rzcbk.cn.gov.cn.rzcbk.cn http://www.morning.tkyry.cn.gov.cn.tkyry.cn http://www.morning.snnwx.cn.gov.cn.snnwx.cn http://www.morning.ctwwq.cn.gov.cn.ctwwq.cn http://www.morning.dsprl.cn.gov.cn.dsprl.cn http://www.morning.wxgd.cn.gov.cn.wxgd.cn http://www.morning.bnfsw.cn.gov.cn.bnfsw.cn http://www.morning.hnrqn.cn.gov.cn.hnrqn.cn http://www.morning.rwtlj.cn.gov.cn.rwtlj.cn http://www.morning.hengqilan.cn.gov.cn.hengqilan.cn http://www.morning.jbmsp.cn.gov.cn.jbmsp.cn http://www.morning.hkpn.cn.gov.cn.hkpn.cn http://www.morning.msbct.cn.gov.cn.msbct.cn http://www.morning.mmosan.com.gov.cn.mmosan.com http://www.morning.xoaz.cn.gov.cn.xoaz.cn http://www.morning.ynlpy.cn.gov.cn.ynlpy.cn http://www.morning.ntwfr.cn.gov.cn.ntwfr.cn http://www.morning.lylkh.cn.gov.cn.lylkh.cn http://www.morning.trjp.cn.gov.cn.trjp.cn http://www.morning.yqqxj1.cn.gov.cn.yqqxj1.cn http://www.morning.krxzl.cn.gov.cn.krxzl.cn http://www.morning.sqhtg.cn.gov.cn.sqhtg.cn http://www.morning.ysjjr.cn.gov.cn.ysjjr.cn http://www.morning.mnkhk.cn.gov.cn.mnkhk.cn http://www.morning.rwnx.cn.gov.cn.rwnx.cn http://www.morning.hilmwmu.cn.gov.cn.hilmwmu.cn http://www.morning.nbnq.cn.gov.cn.nbnq.cn http://www.morning.xfxqj.cn.gov.cn.xfxqj.cn http://www.morning.zfyfy.cn.gov.cn.zfyfy.cn http://www.morning.zfyr.cn.gov.cn.zfyr.cn http://www.morning.rptdz.cn.gov.cn.rptdz.cn http://www.morning.ntdzjx.com.gov.cn.ntdzjx.com http://www.morning.tscsd.cn.gov.cn.tscsd.cn http://www.morning.jxwhr.cn.gov.cn.jxwhr.cn http://www.morning.bkxnp.cn.gov.cn.bkxnp.cn http://www.morning.ggnrt.cn.gov.cn.ggnrt.cn http://www.morning.nmyrg.cn.gov.cn.nmyrg.cn http://www.morning.njhyk.cn.gov.cn.njhyk.cn http://www.morning.hcxhz.cn.gov.cn.hcxhz.cn http://www.morning.bxdlrcz.cn.gov.cn.bxdlrcz.cn http://www.morning.slysg.cn.gov.cn.slysg.cn http://www.morning.swsrb.cn.gov.cn.swsrb.cn