当前位置:网站首页>JS 的 try catch finally 中 return 的执行顺序
JS 的 try catch finally 中 return 的执行顺序
2022-07-06 22:37:00 【豪华手抓饼】
情况一:
finally 中有 return =》只有 finally 的 return 生效。
let a = 1;
let b = 0;
function test() {
try {
let c = a / b;
return c;
} catch (error) {
return "error";
} finally {
return "finally";
}
}
console.log(test()); // finally
function test2() {
try {
let c = a / b;
d++;
return c;
} catch (error) {
return "error";
} finally {
return "finally";
}
}
console.log(test2()); // finally
情况二:
finally 没有 return =》会先执行 finally 的代码,然后再执行 try 或 catch 中的 return。
function test4() {
try {
let c = a / b;
return c;
} catch (error) {
return "error";
} finally {
console.log("finally...");
}
}
console.log(test4());
// finally...
// Infinity
function test3() {
try {
let c = a / b;
d++;
return c;
} catch (error) {
return "error";
} finally {
console.log("finally...");
}
}
console.log(test3());
// finally...
// error
function test5() {
try {
if (b == 0) {
return "b";
}
let c = a / b;
return c;
} catch (error) {
return "error";
} finally {
console.log("finally...");
}
}
console.log(test5());
// finally...
// b
边栏推荐
- 关于01背包个人的一些理解
- Jetson nano配置pytorch深度学习环境//待完善
- Ansible概述和模块解释(你刚走过了今天,而扑面而来的却是昨天)
- 树与图的深度优先遍历模版原理
- The most complete learning rate adjustment strategy in history LR_ scheduler
- acwing 843. n-皇后问题
- How to package the parsed Excel data into objects and write this object set into the database?
- Introduction to the PureMVC series
- A picture to understand! Why did the school teach you coding but still not
- Programmers go to work fishing, so play high-end!
猜你喜欢

offer如何选择该考虑哪些因素

Flask项目使用flask-socketio异常:TypeError: function() argument 1 must be code, not str

Liste des hôtes d'inventaire dans ansible (je vous souhaite des fleurs et de la romance sans fin)

Tree map: tree view - draw covid-19 array diagram

Meow, come, come: do you really know if, if else
[email protected]映射关系问题"/>接口间调用为什么要用json、fastjson怎么赋值的、fastjson [email protected]映射关系问题

Camera calibration (I): robot hand eye calibration

Depth first traversal template principle of tree and graph
![[Android kotlin collaboration] use coroutinecontext to realize the retry logic after a network request fails](/img/e0/04f06d464e77012fbfc919e07cbb66.png)
[Android kotlin collaboration] use coroutinecontext to realize the retry logic after a network request fails

【Android Kotlin协程】利用CoroutineContext实现网络请求失败后重试逻辑
随机推荐
Lessons and thoughts of the first SQL injection
ServiceMesh主要解决的三大痛点
JS variable case output user name
Chapter 9 Yunji datacanvas company won the highest honor of the "fifth digital finance innovation competition"!
使用Thread类和Runnable接口实现多线程的区别
Depth first traversal template principle of tree and graph
[ArcGIS tutorial] thematic map production - population density distribution map - population density analysis
PLC模拟量输出 模拟量输出FB analog2NDA(三菱FX3U)
抖音或将推出独立种草社区平台:会不会成为第二个小红书
【线段树实战】最近的请求次数 + 区域和检索 - 数组可修改+我的日程安排表Ⅰ/Ⅲ
Vscode automatically adds a semicolon and jumps to the next line
Analyse approfondie de kubebuilder
Inventory host list in ansible (I wish you countless flowers and romance)
A detailed explanation of head pose estimation [collect good articles]
Acl2022 | decomposed meta learning small sample named entity recognition
Tree map: tree view - draw covid-19 array diagram
食堂用户菜品关系系统(C语言课设)
JDBC link Oracle reference code
Monitoring cannot be started after Oracle modifies the computer name
acwing 843. N-queen problem