Java exception and exception system

Source: Internet
Author: User

16. Exceptions
16.1 a phenomenon that affects the program's normal operation during program execution.
16.2 exception syntax
try{
code block
}catch (Exception type E) {
}catch (Exception type 2 e2) {
}... {
}finally{
}
Note: Try: A block of code that represents an exception that might occur
Catch: Grab exceptions and handle them
Can crawl multiple exceptions, the range of exceptions to small to large crawl
And only the first matching exception type is executed
Finally: Eventually, the code block in finally executes regardless of whether an exception occurs.
In addition to the virtual machine Stop (system.exit (1)) in this case
Note: The execution order of finally and return: Return is executed first, the returned result is saved in the returned result area, and no return
Then execute the FINALLY,Z and return the results saved in the result area to the caller.
16.3 Throuws throws an exception
A. That is, when the current method does not resolve the exception, the exception must be given to the previous caller to handle
B. Syntax
Access modifier return value type method name (argument list) "throws exception" {
}
17.java Anomaly System
Throwable
--error: (Errors that cannot be handled by the program)
--exception: Errors that can be crawled or thrown with the program
--Check for exceptions (non-runtime Exceptions): Exceptions that occur when compiling truncation
SqlException,
IOException,
ClassNotFoundException
--Non-check exception (run-time exception runtimeexception): The exception that occurs during the run phase
NullPointerException,
ArrayIndexOutOfBoundsException,
ClassCastException
Note: The checked exception is the one that needs to be handled
Run-time exception, can not be handled

Java exception and exception system

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.