diff --git a/lib/_debugger.js b/lib/_debugger.js index 17ac52e57d..f454aa9c4c 100644 --- a/lib/_debugger.js +++ b/lib/_debugger.js @@ -678,6 +678,7 @@ var commands = [ 'kill', 'list', 'scripts', + 'breakOnException', 'breakpoints', 'version' ] @@ -1308,6 +1309,19 @@ Interface.prototype.watchers = function() { } }; +// Break on exception +Interface.prototype.breakOnException = function breakOnException() { + if (!this.requireConnection()) return; + + var self = this; + + // Break on exceptions + this.pause(); + this.client.reqSetExceptionBreak('all', function(err, res) { + self.resume(); + }); +}; + // Add breakpoint Interface.prototype.setBreakpoint = function(script, line, condition, silent) { @@ -1626,12 +1640,6 @@ Interface.prototype.trySpawn = function(cb) { self.setBreakpoint(bp.scriptId, bp.line, bp.condition, true); }); - // Break on exceptions - client.reqSetExceptionBreak('all', function(err, res) { - cb && cb(); - self.resume(); - }); - client.on('close', function() { self.pause(); self.print('program terminated'); @@ -1639,6 +1647,9 @@ Interface.prototype.trySpawn = function(cb) { self.client = null; self.killChild(); }); + + if (cb) cb(); + self.resume(); }); client.on('unhandledResponse', function(res) {