...try ...catch ...finally

The try statement tests a block of code for errors.

The catch statement handles errors.

throw statement to create custom errors.

The finally statement is after the try and catch statements, regardless of whether an exception is triggered, the statement will be executed.

try {
    ...    //异常的抛出
} catch(e) {
    ...    //异常的捕获与处理
} finally {
    ...    //结束处理
}

// 可以在控制台打印一下以下代码。
try{   
	const s = a + b;
 } catch (err){
   console.log(`接收错误`,err)
   console.log(`接收错误 name`,err.name)
   console.log(`接收错误 message`, err.message)
 } finally {
   console.log("finally")
 }

 

 

Guess you like

Origin blog.csdn.net/weixin_69811594/article/details/130205297