Source Analysis VII (Java.lang package of the IllegalArgumentException Class)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.