Java Fundamentals (10)---exceptions

Source: Internet
Author: User
Tags finally block

Anomaly Classification Plots:

Throwable
|--error serious problems that we do not deal with.
|--exception
|--runtimeexception run-time exception, we need to fix the code
|--non-RuntimeException compile-time exception, must be handled, or program compilation does not pass

Common methods for exception objects:

If a program needs to access information about an object in a catch block, it can be obtained by accessing the exception parameter after the catch block. When the Java runtime decides to call a catch block to process the exception object, it assigns the exception object to the exception parameter after the catch block, which the program can use to obtain information about the exception.

GetMessage (): Returns the detailed description string for the exception

Printstacktrace (): Outputs the trace stack information for this exception to the standard error output.

Printstacktrace (PrintStream s): Outputs the trace stack information for this exception to the standard error output.

Getstacktrace (): Returns the trace stack information for this exception.

The special case of finally:

In general, do not use a statement such as return or throw that causes a method to terminate in a finally block.

When a Java program executes a try block, a catch block, it encounters a return or throw statement. Both statements cause the method to end immediately, but the system executes the two statements and does not end the method, but instead finds out whether the exception process contains a finally block, and if there is no finally block, the program executes the return or throw statement immediately, terminating the method. If there is a finally block, the system immediately begins execution of the finaly block----The system will not jump back to execute the try block, the Retrun in the catch block, or the throw statement until the finally block finishes executing If the finally block also uses a return or throw and other statements that cause the method to terminate, the finally block one catty terminates the method, the system will not jump back to execute any code in the try block, catch block.

Custom exceptions
Inherited from exception or runtimeexception, it is only necessary to provide a non-parametric construction and a parameter structure.

Java Fundamentals (10)---exceptions

Related Article

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.