One: illegalargumentexception illegal parameter class, this class inherits the parent class RuntimeException
1 Public 2 class extends RuntimeException
Several constructor methods for overloading are directly calling the constructor of the parent class:
//parameterless constructor, default constructor Publicillegalargumentexception () {Super(); } //constructor with a string of arguments Publicillegalargumentexception (String s) {Super(s); } //parameter is string and throwable two parameter constructors Publicillegalargumentexception (String message, throwable cause) {Super(message, cause); } //constructor with parameter Throwable Publicillegalargumentexception (Throwable cause) {Super(cause); } Private Static Final LongSerialversionuid = -5365630128856068164l;
RuntimeException class is directly inheriting extends exception class
Public classRuntimeExceptionextendsException {Static Final LongSerialversionuid = -7034897190745766939l; Publicruntimeexception () {Super(); } Publicruntimeexception (String message) {Super(message); } Publicruntimeexception (String message, throwable cause) {Super(message, cause); } Publicruntimeexception (Throwable cause) {Super(cause); }
Exception class:
Public classExceptionextendsThrowable {Static Final LongSerialversionuid = -3387516993124229948l; PublicException () {Super(); } PublicException (String message) {Super(message); } PublicException (String message, throwable cause) {Super(message, cause); } PublicException (Throwable cause) {Super(cause); }}
And the exception class is inherited Throwable class
1 // 2 public throwable () {3 fillinstacktrace (); 4 }56// Call the native method, the underlying is C or C + + language implementation 7 Public synchronized native Throwable fillinstacktrace ();
// constructor with argument string, describing exception information Public throwable (String message) { fillinstacktrace (); = message; } Private String Detailmessage;
1 // 2 public throwable (String message, throwable cause) {3 Fillinstacktrace (); 4 Detailmessage = message; 5 this. Cause = cause; 6 }
public throwable (Throwable cause) { fillinstacktrace (); = (cause==nullnull : cause.tostring ()); this. Cause = cause; }
Take a look at the other methods in Throwable:
The details of the exception are the message public String GetMessage () {return detailmessage, encapsulated in the constructor method ; }
Calling the GetMessage method directly, returning the description information of the exception is also public String getlocalizedmessage () { return getMessage (); }
Get this exception object, because this cause exception object is initialized when this is this, it is itself, so if not changed, is null, otherwise causeprivate throwable cause = this; Public Throwable Getcause () { return (cause==this? null:cause); }
Two: Custom exception classes
If we want to customize the exception class, we only need to inherit the RuntimeException or exception class, and then
It is possible to call the constructor of the parent class in the constructor method.
Source Analysis VII (Java.lang package of the IllegalArgumentException Class)