1. Description
(1) For runtime exceptions, they can be processed without explicit processing
(2) For compile-time exceptions , must be processed explicitly
2. Method 1:
try{ // 可能出现异常的代码 }catch(Exption1 e1){ // 处理方式一 }catch(Exption2 e2){ // 处理方式二 }finally{ // 一定要执行的代码 }
Note:
(1) Declared in try Variables, similar to local variables, cannot be called except for try{} statements
(2) The inside of the catch statement handles exception objects: e.getMessage(); e.printStackTrace()
(3) Multiple catch statements can be used. The exception class object thrown in try matches the type of exception class in catch from top to bottom. Once satisfied, the code in catch will be executed. After execution, it will jump out. Multiple catch statements
(4) If the exception is handled, then the subsequent code continues to execute
(5) If the multiple exception types in the catch are in a "parallel" relationship, then the order Both before and after can be used. If multiple exception types in the catch are in an "include" relationship, the subclass must be placed before the parent class for processing. Otherwise, an error will be reported
(6) finally is optional
(7) finally stores code that will definitely be executed regardless of whether there are still unhandled exceptions in try or catch, and whether there is a return statement
(8) try-catch is possible Nested
3. Method 2:
(1) At the declaration of the method, explicitly throw the type of the exception object
(2) Format, such as:
public static void method() throws Exception{}
(3) When an exception occurs inside this method, an object of the exception class will be thrown to the caller of the method
(4) Exception objects can be thrown upward layer by layer until main. Of course, during the upward throwing process, it can be processed through try-catch-finally
The above is the detailed content of How to solve the classification problem of java exception handling. For more information, please follow other related articles on the PHP Chinese website!

Packages and Directories in Java: The logic behind compiler errors In Java development, you often encounter problems with packages and directories. This article will explore Java in depth...

Leetcode ...

JWT and Session Choice: Tradeoffs under Dynamic Permission Changes Many Beginners on JWT and Session...

How to correctly configure apple-app-site-association file in Baota nginx? Recently, the company's iOS department sent an apple-app-site-association file and...

How to understand the classification and implementation methods of two consistency consensus algorithms? At the protocol level, there has been no new members in the selection of consistency algorithms for many years. ...

mybatis-plus...

The difference between ISTRUE and =True query conditions in MySQL In MySQL database, when processing Boolean values (Booleans), ISTRUE and =TRUE...

How to avoid data overwriting and style loss of merged cells when using EasyExcel for template filling? Using EasyExcel for Excel...


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver Mac version
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment