Java common exceptions and Throwable class

Important UncheckedException

abnormal description
ArithmeticException When the exceptional arithmetic condition occurs, Thrown. For example, an integer "divide by zero" throws an instance of this class.
ArrayIndexOutOfBoundsException Access abnormal thrown when an array with an illegal index. If the index is greater than or equal to the array size of the negative, the index is invalid index.
ArrayStoreException Trying to store the wrong type to an object thrown when an array of anomalies.
ClassCastException When you try to cast an object is not an instance of a subclass Thrown.
IllegalArgumentException Thrown to indicate that passed an illegal or incorrect parameter to the method.
IllegalMonitorStateException Thrown to indicate that a thread has attempted to wait on an object's monitor or to notify other objects are waiting for the monitor without owning the specified monitor thread.
IllegalStateException Signal is generated when the illegal or inappropriate time to call the method. In other words, the Java environment, or Java application is not in an appropriate state of the requested operation.
IllegalThreadStateException Thread is not in an appropriate state for requesting thrown required abnormal operation.
IndexOutOfBoundsException Indicating an ordered index (e.g. sorted array, a string, or vector) when thrown out of range.
NegativeArraySizeException If the application tries to create an array with negative size, Thrown.
NullPointerException When an application attempts to use null object where needed Thrown.
NumberFormatException When the application tries to convert a string into a numeric type, but that the string can not be converted into the appropriate format, the thrown exception.
SecurityException Thrown by the security manager to indicate a security violation.
StringIndexOutOfBoundsException String This exception is thrown by the method, or indication index is negative, or greater than the size of the string.
UnsupportedOperationException When the requested operation is not supported Thrown.

Important CheckedException

abnormal description
ClassNotFoundException When an application tries to load a class, you can not find the corresponding class Thrown.
CloneNotSupportedException When the clone cloned object invokes the Object class, but when the object's class can not implement the Cloneable interface Thrown.
IllegalAccessException Deny access to a class, Thrown.
InstantiationException When you try to create an instance of a class using the newInstance method in class Class, but the specified class object because it is an interface or an abstract class can not be instantiated Thrown.
InterruptedException A thread is interrupted by another thread, throw the exception.
NoSuchFieldException Variable requested does not exist.
NoSuchMethodException The method of the request does not exist.

java.lang.Throwable

Important API

Method name Explanation
public Throwable fillInStackTrace() Throwable object stack layers filled with the current call stack level, adding to the stack layers any previous information.
public Throwable getCause() It returns a Throwable object that represents the reason for the exception.
public String getMessage() Returns detailed information about the exception occurred. This message is initialized in the constructor of the class Throwable.
public void printStackTrace() Print toString () result and stack level to System.err, ie the error output stream.
public StackTraceElement[] getStackTrace() It returns an array containing a stack level. Element at index 0 represents the top of the stack, the last element represents a method call stack bottom of the stack.
public String toString() 使用getMessage()的结果返回类的串级名字。

子类API

在这里插入图片描述

其实Error、Exception、RuntimeException这些类都没有额外附加什么方法,基本还是用着java.lang.Throwable的方法。

发布了599 篇原创文章 · 获赞 1211 · 访问量 43万+

Guess you like

Origin blog.csdn.net/weixin_43896318/article/details/104538103