Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Showing JavaScript exception message in Chrome dev tools

I'm using Chrome development tools to debug my JavaScript. When I tell Chrome "Not to pause on exceptions" and load my script, I get an intelligible description of what went wrong with the correct line highlighted:

var back_buffer = goog.dom.getElement('back_buffer').getContext('2d');
  --> "Uncaught TypeError: Cannot call method 'getContext' of null"

OK, it makes sense: there's a typo in the name of my canvas element so 'getElement' returns null.

Now on to my question: when I tell Chrome to 'pause on uncaught exceptions', it still correctly highlights the offending line in my script, but now the nice, intelligible error descriptions is gone! How come? Even in debug mode I'd like to see the error message because it's very helpful. I poked around but couldn't find it anywhere.

Anybody could help here?

like image 559
Lajos Nagy Avatar asked Apr 24 '26 18:04

Lajos Nagy


2 Answers

There does not appear to be good way to do this currently. This is the closest you can get: enter image description here

like image 195
trumank Avatar answered Apr 26 '26 07:04

trumank


The error is not showing because the execution of that script is paused just before it goes into the exception.

It's pausing right before the error so you can debug some things in the console. What i tend to do in the situation you talk about, and the scope variables are not giving any more info, is add some watch expressions or execute some commands in the console.

In your back_buffer case you could for instance add a watch expression like this goog.dom.getElement('back_buffer') so you could see what it resolves to. If that expression causes an error you will see the error message there like you would after the script error occurred.

It might not be completely obvious to some people that when script execution is halted the execution context is the same as the execution context of the script at the time it paused, so all local variables are accessible in the console to console.log() or console.dir() or anything.

When you have pretty print set to on there will be not that much going on on that one line it paused at so mostly you shouldn't have to search for long to get an idea of what's causing the error and why.

Hope it helps, PM5544.

like image 21
PM5544 Avatar answered Apr 26 '26 06:04

PM5544



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!