This getStackTrace() function creates the stack trace of the function from which you've called getStackTrace(). It does not create the stack trace of an error that you've caught. For example, you'd use it to try to figure out how a specific function is being called:
function foo() {
// debug how this is being called
alert(YOUR_NAMESPACE.getStackTrace());
}
Or to add some more detail to an error you raise:
function foo() {
// signal something went wrong
var error = new Error("error in foo");
if (!error.stack)
error.stack = YOUR_NAMESPACE.getStackTrace();
throw error;
}
You can not use it like this:
try {
foo();
} catch (e) {
alert(YOUR_NAMESPACE.getStackTrace(e));
}
Here's a good rundown of what stack information you can get -- and from which browsers -- when an error occurs: Three Painful Ways to Obtain a Stack Trace in Javascript