I have a problem with errors and Promise reject execution times. My code is as follows, but when I run this code in my browser, the output is not well explained (Promise with no catch and when is that error throws?). Can you help?
My browser is Edge (Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0).
btn.click()
Promise.resolve().then(() => {
console.log('1')
setTimeout(() => {
throw new Error('1-1')
})
})
setTimeout(() => {
setTimeout(() => {
throw new Error('55')
})
throw new Error('55-5')
})
Promise.reject(2)
Promise.resolve().then(() => {
setTimeout(() => {
throw new Error('3')
})
})
setTimeout(() => {
Promise.resolve().then(() => {
console.log('4-4')
throw new Error('4')
})
})
setTimeout(() => {
setTimeout(() => {
throw new Error('5')
})
throw new Error('5-5')
})
console.log('6')
throw new Error('7')
setTimeout(() => {
console.log('8')
})
<body>
<button id="btn" onclick="(
() => {
setTimeout(() => {console.log('9') })
throw new Error('10')
}
)()">Button</button>
<div>data</div>
</body>