Exceptions in synchronous style in JavaScript
Synchronous promise syntax supports
exception handling via plain
try-catch
:
async function func() {
try {
let res = await getSmth(2);
console.log(res);
} catch (err) {
console.log(err);
}
}
func();