当前位置:网站首页>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
边栏推荐
- The most complete learning rate adjustment strategy in history LR_ scheduler
- 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
- Introduction to namespace Basics
- STM32封装ESP8266一键配置函数:实现实现AP模式和STA模式切换、服务器与客户端创建
- If you‘re running pod install manually, make sure flutter pub get is executed first.
- 架构实战训练营|课后作业|模块 6
- In depth analysis of kubebuilder
- What is JVM? What are the purposes of JVM tuning?
- Can I specify a path in an attribute to map a property in my class to a child property in my JSON?
- Flask项目使用flask-socketio异常:TypeError: function() argument 1 must be code, not str
猜你喜欢

Read of shell internal value command

九章云极DataCanvas公司蝉联中国机器学习平台市场TOP 3

Basic idea of counting and sorting

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

MySQL数据库(基础篇)

Why do many people misunderstand technical debt

U++ 游戏类 学习笔记

Oracle - views and sequences

Ansible报错:“msg“: “Invalid/incorrect password: Permission denied, please try again.“

System framework of PureMVC
随机推荐
The most complete learning rate adjustment strategy in history LR_ scheduler
Vscode 如何使用内置浏览器?
Local tool [Navicat] connects to remote [MySQL] operation
AttributeError: module ‘torch._ C‘ has no attribute ‘_ cuda_ setDevice‘
Pointer and array are input in function to realize reverse order output
Ansible overview and module explanation (you just passed today, but yesterday came to your face)
How to design API interface and realize unified format return?
【Android Kotlin协程】利用CoroutineContext实现网络请求失败后重试逻辑
How to package the parsed Excel data into objects and write this object set into the database?
Servicemesh mainly solves three pain points
动态生成表格
When knative meets webassembly
关于01背包个人的一些理解
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
Fiance donated 500million dollars to female PI, so that she didn't need to apply for projects, recruited 150 scientists, and did scientific research at ease!
ServiceMesh主要解决的三大痛点
Time complexity & space complexity
JS variable plus
Poor math students who once dropped out of school won the fields award this year
Jetson nano configures pytorch deep learning environment / / to be improved