Exceptions in Java

Source: Internet
Author: User
Tags throwable

1.Throwable:Throwable is the parent class of the error Class (ERR) and the exception class (Exception)2.Error:Console error due to code or system-hard errors3. Exception:Exception is the parent of all specific exceptions because the code itself can potentially cause problems, and running code can cause an exception4. Classification of exceptions:(1). Run-time exception: the code itself is not reported red, but run the program when the console error common run-time exception: java.lang.NullPointerException null pointer exception occurs: null pointer exceptions occur when a method or member variable is called Java.lang.ArrayIndexOutOfBoundsException array out-of-bounds exception occurs because of an array or collection with the lower-corner label out of bounds java.lang.ClassCastException type conversion exception occurred: when the next transformation The Java.lang.NumberFormatException number type conversion exception occurs because a string that cannot be converted to an integer is forcibly converted to an integer (2). Compile-Time Exceptions: Unlike compilation errors, compile-time exceptions occur When the code is compiled, Java detects that the method itself may potentially have an exception, which must be resolved by Try-catch or throws5. Characteristics of the anomaly:When the program runs, if an exception occurs, the program stops immediately and the code behind it does not continue to run6. How to avoid exceptions:(1). Use the try-catch-finally structure (2). Declare the exception by throws keyword and give it to other methods to resolve7. Features of the try-catch-finally structure:(1). Try cannot be omitted, catch and finally exist at least one (2). You can have multiple catch blocks, but you must ensure that their exceptions meet the subclass, parent, or peer relationship (3). It is not appropriate to place too much code in a try block. Typically only the code (4) that is likely to appear an exception is placed. Finally, the part that is bound to execute no matter how the program is run

Exceptions in Java

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.