Binding opcional en `catch`
· Lectura de un minuto
La cláusula catch
de las sentencias try
solía requerir un binding:
try {
doSomethingThatMightThrow();
} catch (exception) {
// ^^^^^^^^^
// ¡Debemos nombrar el binding, incluso si no lo usamos!
handleException();
}
En ES2019, ahora se puede usar catch
sin un binding. Esto es útil si no necesitas el objeto exception
en el código que maneja la excepción.
try {
doSomethingThatMightThrow();
} catch { // → ¡Sin binding!
handleException();
}