๐ง under construction
Last updated 1 year ago
JS โฉ statement โฉ control flow โฉ jump โฉ try-catch-finally
JS โฉ error โฉ handling โฉ try-catch-finally
(statement)
try { ... } // run code that may throw. catch (err) { ... } // error handling (andโจ rethrow) finally { ... } // cleanup code
ไธไฝไฝฟ็จ try๏ผไธๅฎ่ฆ็จ catch(err) ๅปๆใๆๆ็้ฏ่ชคใ๏ผๅฆๅๅฏ่ฝๆๆผๆใ่ชๅทฑๆฒๆ้ ๆ็้ฏ่ชคใ
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.
bare catch clause
in ES2019 and later, the parentheses / (error) identifier in the catch clause can be omitted.
error
error handling
throw
JavaScript: The Definitive Guide โฉ 5.5.7 try/catch/finally
try...catch