JAVA exception handling classification and handling principles

 1. JAVA exception classification

Throwable is the superclass of all errors or exceptions in the Java language. The next layer is divided into Error and Exception

ERROR is an error that cannot be handled well by the program and is not allowed to be caught

Exception is divided into runtime exception (unchecked) and non-runtime exception (checked)

 

Second, the principle of exception handling

1: The bottom layer throws an exception (developer), and the outer layer catches the exception and handles it (user). Improve user experience.

2: If you can't handle exceptions, don't catch them.

3: Catch the exception nearby.

4: Don't unhandle already caught exceptions.

5: Try to judge the abnormality through the program.

6: Custom encapsulation of exceptions (inheriting RunTimeException).

7: Try to catch specific exception classes

 

The first time I wrote a technical blog, it was a bit messy. Please guide me!

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326227557&siteId=291194637