在写代码的时候我们经常需要新建异常,如throw new IllegalStateException("capacity is not less than 0");该异常不需要捕获(在方法前throws 该Exception)。但是有的异常如throw new IOException()需要捕获或抛出异常。主要因为java中异常有两类Runtime(运行时异常)和Checked(编译时异常)。(两种异常的说明见博客http://blog.sina.com.cn/s/blog_68205b190101it3x.html)。
本文介绍了Java中的异常处理机制,区分了运行时异常(Runtime)与编译时异常(Checked)的不同,并通过实例展示了如何创建及使用这两种类型的异常。
3674





