try...catch中,catch加了return,后面的代码是不会执行的

简介: try...catch中,catch加了return,后面的代码是不会执行的
function sum(){
     try {
         console.log(data);
     } catch {  
         console.log('报错了');
            return
         console.log('报错了2');
     }
     console.log('catch外的输出');
}
sum()

catch中加了return,后面的代码是不执行的。


如果不加return,后面的代码则会执行

function sum(){
     try {
         console.log(data);
     } catch {  
         console.log('报错了');
          //  return
         console.log('报错了2');
     }
     console.log('catch外的输出');
}
sum()

目录
相关文章
|
9月前
每日一道面试题之try-catch-finally 中,如果 catch 中 return 了,finally 还会执行吗?
每日一道面试题之try-catch-finally 中,如果 catch 中 return 了,finally 还会执行吗?
118 0
|
12月前
try catch finally,try 里面有 return,finally 还执行吗?
try catch finally,try 里面有 return,finally 还执行吗?
39 0
|
8月前
try和catch的用法
try和catch的用法
55 1
|
9月前
16 # 实现 catch 方法
16 # 实现 catch 方法
41 0
Java 最常见的面试题:try-catch-finally 中,如果 catch 中 return 了,finally 还会执行吗?
Java 最常见的面试题:try-catch-finally 中,如果 catch 中 return 了,finally 还会执行吗?
try catch return语句情况分析
简要讲述一下try catch代码中return语句返回值情况分析
|
编译器
throw后报错,找不到报错处。throw、throws 、try/catch 作用区别,自定义Exception异常,printStackTrace()方法的
throw后报错,找不到报错处。throw、throws 、try/catch 作用区别,自定义Exception异常,printStackTrace()方法的
150 2
|
Java 数据库连接 数据库
try()catch{}自动释放资源
try()catch{}自动释放资源
198 0
|
Java
【学习笔记】【Java】try-catch-finally中,finally是在什么时候执行的:try结束、catch结束、return前
结论:try-catch-finally中,finally执行:try结束、catch结束、return前
174 0
【学习笔记】【Java】try-catch-finally中,finally是在什么时候执行的:try结束、catch结束、return前