Skip to content

Instantly share code, notes, and snippets.

@jay3sh
Created August 20, 2011 10:33
Show Gist options
  • Save jay3sh/1158940 to your computer and use it in GitHub Desktop.
Save jay3sh/1158940 to your computer and use it in GitHub Desktop.
print stack trace anywhere
function foo(args) {
var i, j, k;
// ...
// j acquires some interesting value
// Who called foo when j took this interesting value?
//
var e = new Error('dummy');
var stack = e.stack.replace(/^[^\(]+?[\n$]/gm, '')
.replace(/^\s+at\s+/gm, '')
.replace(/^Object.<anonymous>\s*\(/gm, '{anonymous}()@')
.split('\n');
console.log(stack);
// ...
// rest of the code
}
@maverick0108
Copy link

Hello jay3sh.
I my organization is looking at using the code you have creates (stack-trace-without-exception.js). My legal team will not allowed us to use the code unless there is a valid open source license attached. Would it be possible to add a MIT or BSD license to this code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment