Created
May 12, 2016 18:25
-
-
Save bttmly/431fbd6d1585a28d34e3647d87272484 to your computer and use it in GitHub Desktop.
demonstration of Error.captureStackTrace
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
function Miss () { | |
return new Error("My stack trace is wrong"); | |
} | |
function Hit () { | |
var err = new Error("My stack trace is right"); | |
Error.captureStackTrace(err, Hit); | |
return err; | |
} | |
function errDeeply (Err) { | |
(function fn1 () { | |
(function fn2 () { | |
(function fn3 () { | |
console.log(new Err().stack) | |
})() | |
})() | |
}()) | |
} | |
errDeeply(Miss): | |
errDeeply(Hit); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment