一、unchecked Exception:
即RuntimeException(运行时异常),不需要try…catch…或throws 机制去处理的异常
最常用的五种RuntimeException:
1.ArithmeticException
1 |
int a=0; |
2.ClassCastException:
1 |
Object x = new Integer(0); |
3.IndexOutOfBoundsException
ArrayIndexOutOfBoundsException,
StringIndexOutOfBoundsException
1 |
int [] numbers = { 1, 2, 3 }; |
4.IllegalArgumentException
NumberFormatException
5.NullPointerException
二、Checked Exception:
除了RuntimeException,其他继承自java.lang.Exception的异常统称为Checked Exception
下面是JDK API中列出的异常类:
java.lang.Object
java.lang.Throwable
java.lang.Exception
所有已实现的接口:
Serializable
直接已知子类:
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