This is more of a good practice question. Many people seem to suggest if the app cannot recover from the error, the try/catch should be at the very top of the stack.
const getSomeData2 = () => {
//error in this function, not caught
}
const handleSomeData2 = () => {
try{
//code that doesn't rely on getSomeData2()
//...
//...
let result = getSomeData2()
//code that relies on getSomeData2()
} catch(e) {
//handle error
}
}
handleSomeData2()
I see how in this example, it's redundant to execute the code before let result = getSomeData2()
. Other than efficiency, is there an other reason why errors must be caught at the top of the stack?