当前位置:网站首页>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
边栏推荐
- Windows are not cheap things
- National meteorological data / rainfall distribution data / solar radiation data /npp net primary productivity data / vegetation coverage data
- How to package the parsed Excel data into objects and write this object set into the database?
- Field data acquisition and edge calculation scheme of CNC machine tools
- Canteen user dish relationship system (C language course design)
- Liste des hôtes d'inventaire dans ansible (je vous souhaite des fleurs et de la romance sans fin)
- A row of code r shows the table of Cox regression model
- JS variable
- Jetson nano configures pytorch deep learning environment / / to be improved
- Wechat can play the trumpet. Pinduoduo was found guilty of infringement. The shipment of byte VR equipment ranks second in the world. Today, more big news is here
猜你喜欢
当 Knative 遇见 WebAssembly
Pointer and array are input in function to realize reverse order output
【736. Lisp 语法解析】
A detailed explanation of head pose estimation [collect good articles]
acwing 843. n-皇后问题
Flask项目使用flask-socketio异常:TypeError: function() argument 1 must be code, not str
动态生成表格
【Android Kotlin协程】利用CoroutineContext实现网络请求失败后重试逻辑
Error: No named parameter with the name ‘foregroundColor‘
Gavin teacher's perception of transformer live class - rasa project actual combat e-commerce retail customer service intelligent business dialogue robot microservice code analysis and dialogue experim
随机推荐
Tiktok may launch an independent grass planting community platform: will it become the second little red book
In depth analysis of kubebuilder
The most complete learning rate adjustment strategy in history LR_ scheduler
JS also exports Excel
Flask project uses flask socketio exception: typeerror: function() argument 1 must be code, not str
Local tool [Navicat] connects to remote [MySQL] operation
Oracle - views and sequences
Jetson nano配置pytorch深度学习环境//待完善
leetcode 53. Maximum subarray maximum subarray sum (medium)
Detect when a tab bar item is pressed
STM32封装ESP8266一键配置函数:实现实现AP模式和STA模式切换、服务器与客户端创建
JS variable
Acl2022 | decomposed meta learning small sample named entity recognition
Appium practice | make the test faster, more stable and more reliable (I): slice test
关于01背包个人的一些理解
Vscode 如何使用内置浏览器?
leetcode 53. Maximum Subarray 最大子数组和(中等)
How to package the parsed Excel data into objects and write this object set into the database?
计数排序基础思路
Flask项目使用flask-socketio异常:TypeError: function() argument 1 must be code, not str