avernet avernet - 8 months ago 50
Javascript Question

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.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<script type="text/javascript">

function doError() {
foo.bar = 42;

window.onload = function() {
try {
} catch (e) {
console.log("Error", e);

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


Edit: The URL below is no longer valid. I'm keeping it in order to not invalidate the answer, but 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.

https://developer.chrome.com/devtools/docs/javascript-debugging#pause-on-exceptions - 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. :)