当前位置:网站首页>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
边栏推荐
- mpf2_ Linear programming_ CAPM_ sharpe_ Arbitrage Pricin_ Inversion Gauss Jordan_ Statsmodel_ Pulp_ pLU_ Cholesky_ QR_ Jacobi
- Monitoring cannot be started after Oracle modifies the computer name
- C语言中函数指针与指针函数
- 【736. Lisp 语法解析】
- Servicemesh mainly solves three pain points
- Ansible reports an error: "MSG": "invalid/incorrect password: permission denied, please try again“
- Chapter 9 Yunji datacanvas company won the highest honor of the "fifth digital finance innovation competition"!
- 深入解析Kubebuilder
- Organize five stages of actual attack and defense drill
- 什么是Web3
猜你喜欢

U++ 元数据说明符 学习笔记

Flex layout and usage

Basic knowledge of road loss of 3GPP channel model

Oracle - views and sequences

JDBC link Oracle reference code

Ansible overview and module explanation (you just passed today, but yesterday came to your face)

DFS and BFS concepts and practices +acwing 842 arranged numbers (DFS) +acwing 844 Maze walking (BFS)

DFS和BFS概念及实践+acwing 842 排列数字(dfs) +acwing 844. 走迷宫(bfs)

R语言主成分pca、因子分析、聚类对地区经济研究分析重庆市经济指标

Ansible中的inventory主機清單(預祝你我有數不盡的鮮花和浪漫)
随机推荐
System framework of PureMVC
全国气象数据/降雨量分布数据/太阳辐射数据/NPP净初级生产力数据/植被覆盖度数据
程序员上班摸鱼,这么玩才高端!
[practice leads to truth] is the introduction of import and require really the same as what is said on the Internet
JS input and output
DFS和BFS概念及实践+acwing 842 排列数字(dfs) +acwing 844. 走迷宫(bfs)
Can I specify a path in an attribute to map a property in my class to a child property in my JSON?
Station B boss used my world to create convolutional neural network, Lecun forwarding! Burst the liver for 6 months, playing more than one million
Meaning of 'n:m' and '1:n' in database design
AttributeError: module ‘torch._ C‘ has no attribute ‘_ cuda_ setDevice‘
Read of shell internal value command
When knative meets webassembly
Chapter 9 Yunji datacanvas was rated as 36 krypton "the hard core technology enterprise most concerned by investors"
In depth analysis of kubebuilder
IMS data channel concept of 5g vonr+
[Android kotlin collaboration] use coroutinecontext to realize the retry logic after a network request fails
Factor analysis r practice (with R installation tutorial and code)
mpf2_ Linear programming_ CAPM_ sharpe_ Arbitrage Pricin_ Inversion Gauss Jordan_ Statsmodel_ Pulp_ pLU_ Cholesky_ QR_ Jacobi
Markdown编辑器
【线段树实战】最近的请求次数 + 区域和检索 - 数组可修改+我的日程安排表Ⅰ/Ⅲ