Home > Web Front-end > JS Tutorial > body text

Example analysis of try catch finally in JavaScript exception handling

黄舟
Release: 2017-10-26 09:41:09
Original
1669 people have browsed it

Grammar structure

try catch finally is the ECMAScript-262 third edition standard that provides exception handling mechanism. The grammar structure is as follows:


1 try{
2 //可能会发生的错误代码
3 }
4 catch(error){
5 //错误处理
6 }finally{
7  //无论是否有异常都会执行
8 }
Copy after login

Grammar and Like most languages ​​such as java.net, if the try{} code block catches an exception, the catch block will get an error message object (an instance of Error).

We should put the code that may cause errors in the try block, and error handling in the catch block; in js, if an error occurs in the <script></script> code block and there is no If the exception is caught, the subsequent code of the current

Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!