Statements

try statement

Try the free JavaScript compiler

Executes protected statements and handles thrown values with catch, finally or both. Synchronous catch does not automatically handle later asynchronous failures.

Formal Syntax & Structure

javascript syntaxjavascript
try { statements } catch (error) { recovery }

Working Example

Example Snippetjavascript
try { console.log("ok"); } catch(e) { console.log("bad"); }
JavaScript Reference