Note that chromium/chrome (other browsers using V8), and also Firefox do have a convenient interface to get a stacktrace through a stack property on Error objects.
try {
// Code throwing an exception
} catch(e) {
console.log(e.stack);
}
It applies for the base exceptions as well as for the ones you throw yourself. (Considered that you use the Error class, which is anyway a good practice).
See details on V8 documentation