Skip to content

Instantly share code, notes, and snippets.

@tanhauhau
Created March 24, 2019 12:01
Show Gist options
  • Save tanhauhau/1590f036d012fd01fdef7f0b27e0638a to your computer and use it in GitHub Desktop.
Save tanhauhau/1590f036d012fd01fdef7f0b27e0638a to your computer and use it in GitHub Desktop.
throw an error to get stack
let _value;
Object.defineProperty(obj, 'awesome', {
get: () => {
try {
// intentionally throw an Error to get the call stack
throw new Error();
} catch (error) {
// stack is the stack trace,
// containing error message and the stack
const stack = error.stack;
// print the callee stack
console.log(
stack
.split('\n')
.slice(2)
.join('\n')
);
}
return _value;
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment