โคด๏ธtry-catch-finally
๐ง under construction
JS โฉ statement โฉ control flow โฉ jump โฉ try-catch-finally
try { ... } // run code that may throw.
catch (err) { ... } // error handling (andโจ rethrow)
finally { ... } // cleanup codeไธไฝไฝฟ็จ try๏ผไธๅฎ่ฆ็จ catch(err) ๅปๆใๆๆ็้ฏ่ชคใ๏ผๅฆๅๅฏ่ฝๆๆผๆใ่ชๅทฑๆฒๆ้ ๆ็้ฏ่ชคใโ
try {
noSuchFunc(); // โ ReferenceError (not catched)
} catch(err) {
// `console.log(err)` omitted ... (dangerous)โ
// or, `throw err` omitted ...
}
// the code will continue executing happilyโif a finally clause issues a return statement, the method returns normally, even if an exception has been thrown and has not yet been handled.
Last updated
Was this helpful?