<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">可以是</span>
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">try{}+catch{}</span>
try{}+catch{}+finally{}
try{}+finally{}
三种形式
只要有finally ,肯定就会执行finally语句
下面是几个例子:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"></meta>
<title></title>
</head>
<body>
<script>
try{
try{throw new Error("oops");}
finally{console.log("finally");}
}
catch(ex){console.error("outer",ex.message);}
</script>
</body>
</html>
如果嵌套在里面的try{}catch{}finally{}语句没有catch处理异常,则会在外面处理,但在外面捕获之前会先执行里面的finally语句。如果里面有了catch捕获异常,则不会再在外面处理。