java提供了两种异常机制。一种是运行时异常(RuntimeExepction),一种是检查式异常(checked execption)。
检查式异常:我们经常遇到的IO异常及sql异常就属于检查式异常。对于这种异常,java编译器要求我们必须对出现的这些异常进行catch 所以 面对这种异常不管我们是否愿意,只能自己去写一堆catch来捕捉这些异常。
JDK1.7中有:
EOFException 文件已结束异常
FileNotFoundException 文件未找到异常
SQLException 操作数据库异常
IOException 输入输出异常
NoSuchMethodException 方法未找到异常
运行时异常:我们可以不处理。当出现这样的异常时,总是由虚拟机接管。比如:我们从来没有人去处理过NullPointerException异常,它就是运行时异常,并且这种异常还是最常见的异常之一。
在JDK1.7中java.lang.RuntimeException有如下子类:
AnnotationTypeMismatchException,
ArithmeticException, 算术异常类
ArrayStoreException,数据存储异常,写数组操作时,对象或数据类型不兼容
BufferOverflowException,
BufferUnderflowException,
CannotRedoException,
CannotUndoException,
ClassCastException, 类型强制转换异常
CMMException,
ConcurrentModificationException,
DataBindingException,
DOMException,
EmptyStackException,
EnumConstantNotPresentException,
EventException,
FileSystemAlreadyExistsException,
FileSystemNotFoundException,
IllegalArgumentException,(子类NumberFormatException )
IllegalMonitorStateException,
IllegalPathStateException,
IllegalStateException,
IllformedLocaleException,
ImagingOpException,
IncompleteAnnotationException,
IndexOutOfBoundsException, 数组下标越界异常
JMRuntimeException,
LSException,
MalformedParameterizedTypeException,
MirroredTypesException,
MissingResourceException,
NegativeArraySizeException, 数组负下标异常
NoSuchElementException,
NoSuchMechanismException,
NullPointerException, 空指针异常类
ProfileDataException,
ProviderException,
ProviderNotFoundException,
RasterFormatException,
RejectedExecutionException,
SecurityException, .违背安全原则异常
SystemException,
TypeConstraintException,
TypeNotPresentException,
UndeclaredThrowableException,
UnknownEntityException,
UnmodifiableSetException,
UnsupportedOperationException, 不支持的操作异常
WebServiceException,
WrongMethodTypeException