当前位置:网站首页>Understand the execution sequence of try catch finally in one diagram
Understand the execution sequence of try catch finally in one diagram
2022-06-25 15:59:00 【Favorite grapes】
What is? try-catch-finally
yes java Is used to catch exceptions , And handle exceptional blocks .
- try In the block are the codes that may cause exceptions
- catch The possible exceptions are placed in the block
- finally The block contains code that must be executed
Understand the execution sequence with a picture

Use scenarios ( Database operation as an example )
When accessing a database , An error may occur during execution , At this point through try-catch Block for processing
DataBase db;
try {
User user = db.getUser();
return user;
} catch (DBException e) {
e.printStack();
return null;
} finally {
db.close();
}
Detailed conclusion
- finally There is... In the block return sentence , Returns the finally Medium return Value
- No matter what catch Block or try Whether there is in the block return sentence ,finally The statement in must execute
- finally in return When the sentence is , The compiler will warn , But there is no error .
边栏推荐
猜你喜欢

Brief object memory layout

The release of autok3s v0.5.0 continues to be simple and friendly

揭秘GaussDB(for Redis):全面对比Codis

B站付费视频使up主掉粉过万

Source code analysis of nine routing strategies for distributed task scheduling platform XXL job

Based on neural tag search, the multilingual abstracts of zero samples of Chinese Academy of Sciences and Microsoft Asiatic research were selected into ACL 2022
Power representation in go language
Gold three silver four, an article to solve the resume and interview
Practice of geospatial data in Nepal graph

Sleep formula: how to cure bad sleep?
随机推荐
The style of the mall can also change a lot. DIY can learn about it!
剑指 Offer 09. 用两个栈实现队列
镁光256Gb NAND Flash芯片介绍
Golang open source streaming media audio and video network transmission service -lal
Lifeifei's team applied vit to the robot, increased the maximum speed of planning reasoning by 512 times, and also cued hekaiming's MAE
Programmer vs hacker thinking | daily anecdotes
Practice of geospatial data in Nepal graph
MySQL modify field statement
Finally, we can figure out whether the binding event in the tag is bracketed or not
Mark the same items in the Li list in red
Classic deadlock scenario of multithreading and its solution (philosopher dining problem)
异步处理容易出错的点
f_read 函数[通俗易懂]
基于深度Q学习的雅达利打砖块游戏博弈
Report on Hezhou air32f103cbt6 development board
剑指 Offer 10- I. 斐波那契数列
QC, QA, IPQC, JQE, DQA, SQE, DQC, MQC, IQC, FQC, OQC
MySQL修改字段语句
Jz-065 path in matrix
Most commonly used SQL statements