Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js try without catch

/*
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 { };

/*

You still need a catch block, but it can be empty and you don't need to pass any variable. 
If you don't want a catch block at all, you can use the try/finally, 
but note that it won't swallow errors as an empty catch does.
*/
try {
  throw new Error("This WILL get logged");
} finally {
  console.log("This syntax does not swallow errors");
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #js #catch
ADD COMMENT
Topic
Name
5+6 =