JavaScript: A simpler JavaScript try/catch worth knowing about
Last updated: 7th March 2023Introduction
Make sure you have a valid use case before doing this! But optional catch binding is a little feature worth knowing about:
Before, with the catch binding:
try {
await fetch();
} catch (err) {
console.log(`No that didn't work`);
}
After, without the catch binding:
try {
await fetch();
} catch {
console.log(`No that didn't work`);
}
Supported in all modern web browsers. Check here for browser support.