JavaScript: Is there a way to get Chrome to break on all errors?

JavaScript: Is there a way to get Chrome to break on all errors?

I am looking for an equivalent in Chrome to the “break on all errors” functionality of Firebug. In the Scripts tab, Chrome has a “pause on all exceptions”, but this is not quite the same as breaking on all errors.
For instance, when loading a page with the following code, I would like Chrome to break on the line foo.bar = 42. Instead, even when enabling the “Pause on all exceptions”, I don’t get the expected result.







You can try the code pasted above on this page or using this jsFiddle.

Solutions/Answers:

Solution 1:

Edit: The original link I answered with is now invalid.The newer URL would be https://developers.google.com/web/tools/chrome-devtools/javascript/add-breakpoints#exceptions as of 2016-11-11.

I realize this question has an answer, but it’s no longer accurate. Use the link above ^


(link replaced by edited above) – you can now set it to break on all exceptions or just unhandled ones. (Note that you need to be in the Sources tab to see the button.)

Chrome’s also added some other really useful breakpoint capabilities now, such as breaking on DOM changes or network events.

Normally I wouldn’t re-answer a question, but I had the same question myself, and I found this now-wrong answer, so I figured I’d put this information in here for people who came along later in searching. 🙂

Solution 2:

I got trouble to get it so I post pictures showing different options:

Chrome 71.0.3578.98 [18 December 2018]

Very very similar UI since at least Chrome 38.0.2125.111 [11 December 2014]

In tab Sources :
enter image description here
Screenshot from Chrome 50.0.2661.75

When button is activated, you can Pause On Caught Exceptions with the checkbox below:
enter image description here


Previous versions

Chrome 32.0.1700.102 [03 feb 2014]

enter image description here

enter image description here
enter image description here
enter image description here

Chrome 27.0.1453.93 Stable

Debug options

Solution 3:

This is now supported in Chrome by the “Pause on all exceptions” button.

To enable it:

  • Go to the “Sources” tab in Chrome Developer Tools
  • Click the “Pause” button at the bottom of the window to switch to “Pause on all exceptions mode”.

Note that this button has multiple states. Keep clicking the button to switch between

  • “Pause on all exceptions” – the button is colored light blue
  • “Pause on uncaught exceptions”, the button is colored purple.
  • “Dont pause on exceptions” – the button is colored gray

Solution 4:

Just about any error will throw an exceptions. The only errors I can think of that wouldn’t work with the “pause on exceptions” option are syntax errors, which happen before any of the code gets executed, so there’s no place to pause anyway and none of the code will run.

Apparently, Chrome won’t pause on the exception if it’s inside a try-catch block though. It only pauses on uncaught exceptions. I don’t know of any way to change it.

If you just need to know what line the exception happened on (then you could set a breakpoint if the exception is reproducible), the Error object given to the catch block has a stack property that shows where the exception happened.

Solution 5:

Unfortunately, it the Developer Tools in Chrome seem to be unable to “stop on all errors”, as Firebug does.

Related:  How can I lock the first row and first column of a table when scrolling, possibly using JavaScript and CSS?