Exception Handling (Try-catch)

Source: Internet
Author: User

An exception is a problem that occurs during the execution of a program.

In order for the program to run efficiently, we usually throw exceptions where we think it might be wrong when we write the program. When we call the method, we'll handle it abnormally.

We generally use try{protected code}catch (exception name M) {capture block}finally{always executed code block}, where try{} can throw multiple exceptions.

The usual exception is nullpointexception (null pointer exception), arrayindexoutofboundsexception (array subscript out of bounds),arithmeticexception(mathematical operation exception)

When an exception occurs, the corresponding catch is immediately skipped and the corresponding catch statement is not executed when the TRY statement is executed normally.

log4j (Popular open source logging tool)

Mainly used to record some important operational information of the system, to monitor the operation of the system, to help users to detect and avoid possible problems in advance, or after a problem, according to the log to find the reason

DEBUG, INFO, WARN, error, and fatal are among the 5 error levels

Custom exceptions

Access modifier + Optional trim + return value + method name (parameter) throws esception{}

There are many types of subclasses that are directly known to the exception class, including the 3 above. When we customize exceptions, we can create a class that inherits the exception class and constructs a function in the created class

Public Exception (String message) {} Constructs a new exception with the specified details.

Exception Handling (Try-catch)

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.