try {} without catch {} possible in JavaScript? try {} without catch {} possible in JavaScript? javascript javascript

try {} without catch {} possible in JavaScript?


A try without a catch clause sends its error to the next higher catch, or the window, if there is no catch defined within that try.

If you do not have a catch, a try expression requires a finally clause.

try {    // whatever;} finally {    // always runs}


It's possible to have an empty catch block, without an error variable, starting with ES2019. This is called optional catch binding and was implemented in V8 v6.6, released in June 2018. The feature has been available since Node 10, Chrome 66, Firefox 58, Opera 53 and Safari 11.1.

The syntax is shown below:

try {  throw new Error("This won't show anything");} catch { };