Is it normal that I get an unhandled exception error from a reject(new SomeKindOfError())
within a promise while debugging in VS Code, but not when I'm not debugging? Or is there something wrong from my code structure?
From what I have learned from several tutorials about promises and stackoverflow answers, a Promise#catch()
at then end of a promise chain is enough to catch a rejection that might occur in the chain. But why is it still marked as an unhandled exception by the debugger?
Here's the structure I used:
function returnAPromise(): Promise<any> {
return new Promise<any>((resolve, reject) => {
// do something here
if (isConditionMet) {
resolve()
} else {
reject(new SomeKindOfError()) // debugger breaks here
}
})
}
someElement.onSomeEvent(() => {
// only care about the errors that might occur
returnAPromise().catch((error) => {
if (error instanceof SomeKindOfError) {
// perform necessary actions when this error occurred
}
})
})
P.S. I already tried out debugging without performing break when an unhandled exception is encountered but it kind of defeats the purpose of using the debugger: to check out for unhandled exception that might occur.
Edit:
Also, I tried calling returnAPromise()
without a catch and that one prints a warning in the debugger console saying rejected promise not handled within 1 second
.