最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Errors and Promise reject execution times - Stack Overflow

programmeradmin4浏览0评论

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>
发布评论

评论列表(0)

  1. 暂无评论