TERMtm
TERMtm

Reputation: 1933

How to Debug on Exception handled by a specific Try-Catch

While not exclusive to this situation, suppose you have a tool you use, which exposes its API by calling code that you provide. Such as Gulp, for instance.

As it does its work, the library will enclose it's pipeline, very early, in something like...

try { 
    library.doSomethingWith( input )
} 
catch(err){ 
    throw library.prettify(err) 
}

When "internal" errors do hit (often caused in user-land), it may help, rethrowing some potentially more legible error to console. However, if I decide I would like to step through the error in Chrome DevTools or preferred debugging interface, I can't do that. This is because the particular error I care about has "collapsed" into err and the Error{} re-thrown has it's own, useless, live stack-trace.

In some situations this is ok because you can simply break on all exceptions. However there is a major drawback when using libraries complex enough to have asynchronous behavior. As far as I know, you cannot filter out procedural errors which certain libraries and even the node runtime will throw and catch by rote, literally per-tick.

More often than not, when I pause on caught exceptions, I will persistently hit some variant of

try {
    throw new Error()
} catch {
    //transcend annoyance
}

buried deeply in a core dependency.

So with all that said, are there ways to intercept a catch before the error is consumed? While I figure such a feature wouldn't be readily available in the major debuggers, are there commands in the Node Debugger API or special techniques to effectively do one of the following?

It would be a major boost for moral and productivity if errors could be targeted in any of these ways.

Upvotes: 0

Views: 3064

Answers (1)

jasmin_makasana
jasmin_makasana

Reputation: 482

You must be knowing this but anyway,

You can use following option to break the execution whenever some error occurs.

enter image description here

Upvotes: 3

Related Questions