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)