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

javascript - VS-Code won't pause debugger on exception inside Promise - Stack Overflow

programmeradmin0浏览0评论

Please consider the following code:

new Promise((resolve, reject) => {
   breaksomething() //won't pause
})
breaksomething() //pause as expected!

I am expecting my debugger to halt execution - because of an undefined function - at the line breaksomething() inside the promise... However I am only getting the following error output:

"ReferenceError: breaksomething is not defined"

(without pausing). Everywhere else the debugger is pausing as expected when an exception is encountered, the problem is only inside a Promise scope. I do have both All Exceptions and Uncaught Exceptions ticked under breakpoints.

I am using:
Visual Studio Code 1.17.2
Node 8.8.1
Inspector debugger

Please consider the following code:

new Promise((resolve, reject) => {
   breaksomething() //won't pause
})
breaksomething() //pause as expected!

I am expecting my debugger to halt execution - because of an undefined function - at the line breaksomething() inside the promise... However I am only getting the following error output:

"ReferenceError: breaksomething is not defined"

(without pausing). Everywhere else the debugger is pausing as expected when an exception is encountered, the problem is only inside a Promise scope. I do have both All Exceptions and Uncaught Exceptions ticked under breakpoints.

I am using:
Visual Studio Code 1.17.2
Node 8.8.1
Inspector debugger

Share Improve this question edited Nov 6, 2017 at 5:06 Adrita Sharma 22.2k10 gold badges74 silver badges83 bronze badges asked Oct 27, 2017 at 12:18 PierrePierre 1,6673 gold badges21 silver badges33 bronze badges 3
  • Where are you adding definition for breaksomething()? – Tatarin Commented Oct 27, 2017 at 12:19
  • There is no definition - I want to create an exception. – Pierre Commented Oct 27, 2017 at 12:42
  • 1 Seems like this happens because Promise is implemented in a native library and the calling happens of the function happens from that native library. The exception is send back there and hence not caught by VSC – Tarun Lalwani Commented Oct 30, 2017 at 18:15
Add a comment  | 

3 Answers 3

Reset to default 11

UPDATE Per latest update on a known issue from Microsoft team it was a known issue in VS code.

You have to UNCHECK All Exceptions and Uncaught Exceptions in breakpoints settings in VS code in order for that to work

After debugging I found that this is happening because Promise library is implement in Native code

So when you create a Promise, the function inside is actually called by the Native code and the exception goes back to it. This might be one of the reasons that it is not caught by VS debugger.

Is it impossible to do so? Well WebStorm from JetBrains is able to break on such exceptions also. Now how they do it and why VS Code is not able to do it, is beyond my understanding. It would be best to open a issue against VS code and refer that WebStorm does it. So it is technically possible to break on such exceptions

I am still unclear why this issue is happening but I found a workaround. Just install bluebird and add the following in the initialisation code of your app:

global.Promise = require("bluebird");  

...this will override the default nodejs Promise and break as expected when "All exceptions" is ticked

发布评论

评论列表(0)

  1. 暂无评论