I was wondering if there is a way to not specify the argument when doing a JS try/catch. Every time I try this though, the try/catch doesn't work.
The working version:
try{
//Breaking code
} catch(e){
//Nothing happens here
}
What I have in mind (No 'e'):
try{
//Breaking code
} catch(){
//Nothing happens here
}
In Node.js, this feature is called Optional Catch Binding and is supported since Node.js version 10.3, see https://node.green.
In Typescript, this is allowed since version 2.5.
The proposal is currently Stage 4, meaning that its implementation is finished and it is guaranteed to be included into the next version of the ECMAScript standard.
So this is a perfectly legitimate syntax now according to the standard if you are using Node.js or transpiling your browser code using Babel:
try {
} catch {
// No need for the `(error)` after `catch`!
}