I am kind of new to async/await in javascript by have used suspend functionalities in Kotlin before. Is there any way to await and catch error if any in js. (without writing try catch). If not what is the right way to do this.
For example consider this snippet, async function a:
let a = async () => {
// does io and returns result
}
Now, consider a function b which calls a. Can I write it in this clean way:
let a = async () => {
const result_of_a = (await a()).catch(() => { // handle error })
// work with `result_of_a`
}
Rather than
let a = async () => {
var result_of_a = null
try {
result_of_a = await a()
} catch (e) {
}
// work with `result_of_a`
}
Is there any other pretty way of writing the above sub-routine