Java SE的异常分类

来源:互联网 发布:破解网络摄像头 编辑:程序博客网 时间:2024/05/09 08:24

Java有两种异常:

一种是未检查异常(Unchecked ExepctionRuntimeExepction),

一种是已检查异常(checked execption)。


已检查异常:我们经常遇到的IO异常及sql异常就属于已检查异常。对于这种异常,java编译器要求我们必须对出现的这些异常进行catch,所以 面对这种异常不管我们是否愿意,只能自己去写一堆catch来捕捉这些异常。


未检查异常:我们可以不处理。当出现这样的异常时,总是由虚拟机接管。比如:我们从来没有人去处理过NullPointerException异常,它就是运行时异常,并且这种异常还是最常见的异常之一。


RuntimeExecption在java.lang包下,

AnnotationTypeMismatchException, 
ArithmeticException, 
ArrayStoreException, 
BufferOverflowException, 
BufferUnderflowException, 
CannotRedoException, 
CannotUndoException, 
ClassCastException, 
CMMException, 
ConcurrentModificationException, 
DOMException, 
EmptyStackException, 
EnumConstantNotPresentException, 
EventException, 
IllegalArgumentException, 
IllegalMonitorStateException, 
IllegalPathStateException, 
IllegalStateException, 
ImagingOpException, 
IncompleteAnnotationException, 
IndexOutOfBoundsException, 
JMRuntimeException, 
LSException, 
MalformedParameterizedTypeException, 
MirroredTypeException, 
MirroredTypesException, 
MissingResourceException, 
NegativeArraySizeException, 
NoSuchElementException, 
NoSuchMechanismException, 
NullPointerException, 
ProfileDataException, 
ProviderException, 
RasterFormatException, 
RejectedExecutionException, 
SecurityException, 
SystemException, 
TypeConstraintException, 
TypeNotPresentException, 
UndeclaredThrowableException, 
UnknownAnnotationValueException, 
UnknownElementException, 
UnknownTypeException, 
UnmodifiableSetException, 
UnsupportedOperationException, 
WebServiceException


常见的未检查异常 

ClassCastException(类转换异常)

IndexOutOfBoundsException(数组越界)

NullPointerException(空指针)

ArrayStoreException(数据存储异常,操作数组时类型不一致)

还有IO操作的BufferOverflowException异常


常见的已检查异常

SQLException

UnsupportedEncodingException

IOException




0 0
原创粉丝点击