Last active
August 29, 2015 14:06
-
-
Save csnover/5900a60070d9a40fc7d8 to your computer and use it in GitHub Desktop.
What should the first line of an error stack trace be, in different scenarios?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// scenario 1 | |
var error = new Error('foo'); | |
error.stack; // first line = ? | |
// scenario 2 | |
var error = new Error('foo'); | |
error.message = 'bar'; | |
error.stack; // first line = ? | |
// scenario 3 | |
var error = new Error('foo'); | |
error.stack; | |
error.message = 'bar'; | |
error.stack; // first line = ? | |
// scenario 4 | |
var error = new Error('foo'); | |
error.message = 'bar'; | |
try { | |
throw error; | |
} | |
catch (error) { | |
error.stack; // first line = ? | |
} | |
// scenario 5 | |
var error = new Error('foo'); | |
try { | |
throw error; | |
} | |
catch (error) { | |
error.message = 'bar'; | |
error.stack; // first line = ? | |
} | |
// scenario 6 | |
function BarError() { | |
Error.apply(this, arguments); | |
this.message = 'bar'; | |
} | |
BarError.prototype = new Error(); | |
BarError.prototype.name = 'BarError'; | |
BarError.prototype.constructor = BarError; | |
var error = new BarError(); | |
try { | |
throw error; | |
} | |
catch (error) { | |
error.stack; // first line = ? | |
} | |
// scenario 7 | |
function BarError() { | |
Error.apply(this, arguments); | |
this.message = 'bar'; | |
} | |
BarError.prototype = Object.create(Error.prototype); | |
BarError.prototype.name = 'BarError'; | |
BarError.prototype.constructor = BarError; | |
var error = new BarError(); | |
try { | |
throw error; | |
} | |
catch (error) { | |
error.stack; // first line = ? | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
IE 11—
Old V8 (Node.js 0.10)—
New V8 (Node.js master, Chrome 36, Opera 24)—
Firefox 32—
Safari 7.0.6—