当前位置:网站首页>The execution order of return in JS' try catch finally
The execution order of return in JS' try catch finally
2022-07-07 05:02:00 【Luxury grab cake】
Situation 1 :
finally There is return =》 Only finally Of return take effect .
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
Situation two :
finally No, return =》 Will execute first finally Code for , And then execute try or catch Medium 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
边栏推荐
- If you ask me about R code debugging, I will tell you head, STR, help
- [ArcGIS tutorial] thematic map production - population density distribution map - population density analysis
- STM32F103 realize IAP online upgrade application
- 九章云极DataCanvas公司获评36氪「最受投资人关注的硬核科技企业」
- JS also exports Excel
- 高手勿进!写给初中级程序员以及还在大学修炼的“准程序员”的成长秘籍
- R语言主成分pca、因子分析、聚类对地区经济研究分析重庆市经济指标
- App embedded H5 --- iPhone soft keyboard blocks input text
- 【愚公系列】2022年7月 Go教学课程 005-变量
- Ansible中的inventory主机清单(预祝你我有数不尽的鲜花和浪漫)
猜你喜欢

Ansible中的inventory主機清單(預祝你我有數不盡的鮮花和浪漫)

C语言中函数指针与指针函数

01 machine learning related regulations

A simple and beautiful regression table is produced in one line of code~

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

一文搞懂常见的网络I/O模型

【736. Lisp 语法解析】

AttributeError: module ‘torch._ C‘ has no attribute ‘_ cuda_ setDevice‘

Introduction to the PureMVC series

Why do many people misunderstand technical debt
随机推荐
JS also exports Excel
Analyse approfondie de kubebuilder
5G VoNR+之IMS Data Channel概念
九章云极DataCanvas公司摘获「第五届数字金融创新大赛」最高荣誉!
IMS data channel concept of 5g vonr+
STM32 encapsulates the one key configuration function of esp8266: realize the switching between AP mode and sta mode, and the creation of server and client
Can I specify a path in an attribute to map a property in my class to a child property in my JSON?
Field data acquisition and edge calculation scheme of CNC machine tools
How to choose an offer and what factors should be considered
Why do many people misunderstand technical debt
U++4 接口 学习笔记
Vscode automatically adds a semicolon and jumps to the next line
深入解析Kubebuilder
Oracle -- 视图与序列
offer如何选择该考虑哪些因素
窗口可不是什么便宜的东西
使用知云阅读器翻译统计遗传学书籍
3.基金的类型
Appium practice | make the test faster, more stable and more reliable (I): slice test
Local tool [Navicat] connects to remote [MySQL] operation