Java language Core-basics of capturing a single exception __java using Try-catch

Source: Internet
Author: User

What is an exception: abnormal, different from normal, not grammatical error.
The exception is not a grammatical error, the syntax is wrong, the compilation can not pass, will not produce bytecode files, can not run at all.

Abnormal condition (after program interruption)
1, Error: errors, generally refers to the JVM-related unrecoverable errors, such as system crashes, memory overflow, etc.;
2, Exception: Indicates an exception, refers to an abnormal situation in the program, the problem can be repaired (handling exceptions) using Try-catch to catch a single exception

try{
    Code
}catch (Exception type E) {} for which an exception might occur

Experiment:

   public static void Main (string[] args) {
        System.out.println ("Begin ...");

        try {
            int ret = 10/0;
            SYSTEM.OUT.PRINTLN ("result =" +ret);
        } catch (ArithmeticException e) {
            System.out.println ("abnormal!!!");
            System.out.println (e);
        }

        System.out.println ("End ...");
    }

Console execution Results:

Begin ...
Out of the ordinary!!!
Java.lang.ArithmeticException:/By zero end
...

Process finished with exit code 0

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.