JAVA受检异常和非受检异常举例
受检异常和非受检异常(运行时异常)举例
RuntimeException(即非受检异常):
RuntimeException在默认情况下会得到自动处理,所以通常用不着捕获RuntimeException。RuntimeException是那些可能在Java虚拟机正常运行期间抛出的异常的超类,可能在执行方法期间抛出但未被捕获的RuntimeException的任何子类都无需在throws子句中进行声明。
java.lang.ArithmeticException
java.lang.ArrayStoreExcetpion
java.lang.ClassCastException
java.lang.EnumConstantNotPresentException
java.lang.IllegalArgumentException
java.lang.IllegalThreadStateException
java.lang.NumberFormatException
java.lang.IllegalMonitorStateException
java.lang.IllegalStateException
java.lang.IndexOutOfBoundsException
java.lang.ArrayIndexOutOfBoundsException
java.lang.StringIndexOutOfBoundsException
java.lang.NegativeArraySizeException
java.lang.NullPointerException
java.lang.SecurityException
java.lang.TypeNotPresentException
java.lang.UnsupprotedOperationException
受检异常:
除了RuntimeException以外的异常,都属于CheckedException,它们都在java.lang库内部定义。Java编译器要求程序必须捕获或声明抛出这种异常。一个方法必须通过throws语句在方法的声明部分说明它可能抛出但并未捕获的所有CheckedException。
java.lang.ClassNotFoundException
java.io.FileNotFoundException
java.io.IOException
java.sql.SQLException
java.net.SocketException
java.lang.CloneNotSupportedException
java.lang.IllegalAccessException
java.lang.InterruptedException
java.lang.NoSuchFieldException
java.lang.NoSuchMetodException
(附)Java API中Exception的直接已知子类:
AclNotFoundException
ActivationException
AlreadyBoundException
ApplicationException
AWTException
BackingStoreException
BadAttributeValueExpException
BadBinaryOpValueExpException
BadLocationException
BadStringOperationException
BrokenBarrierException
CertificateException
ClassNotFoundException
CloneNotSupportedException
DataFormatException
DatatypeConfigurationException
DestroyFailedException
ExecutionException
ExpandVetoException
FontFormatException
GeneralSecurityException
GSSException
IllegalAccessException
IllegalClassFormatException
InstantiationException
InterruptedException
IntrospectionException
InvalidApplicationException
InvalidMidiDataException
InvalidPreferencesFormatException
InvalidTargetObjectTypeException
InvocationTargetException
IOException
JAXBException
JMException
KeySelectorException
LastOwnerException
LineUnavailableException
MarshalException
MidiUnavailableException
MimeTypeParseException
MimeTypeParseException
NamingException
NoninvertibleTransformException
NoSuchFieldException
NoSuchMethodException
NotBoundException
NotOwnerException
ParseException
ParserConfigurationException
PrinterException
PrintException
PrivilegedActionException
PropertyVetoException
RefreshFailedException
RemarshalException
RuntimeException
SAXException
ScriptException
ServerNotActiveException
SOAPException
SQLException
TimeoutException
TooManyListenersException
TransformerException
TransformException
UnmodifiableClassException
UnsupportedAudioFileException
UnsupportedCallbackException
UnsupportedFlavorException
UnsupportedLookAndFeelException
URIReferenceException
URISyntaxException
UserException
XAException
XMLParseException
XMLSignatureException
XMLStreamException
XPathException