stacktrace() Function for JavaScript Exceptions
Determining a JavaScript stack trace is accessible when JavaScript exceptions occur. However, acquiring a stack trace for custom exceptions thrown manually may require specific techniques.
For custom exceptions, the following script can be employed:
function stacktrace() { function st2(f) { return !f ? [] : st2(f.caller).concat([f.toString().split('(')[0].substring(9) + '(' + f.arguments.join(',') + ')']); } return st2(arguments.callee.caller); }
Additionally, modern browsers offer the console.trace() function for capturing stack traces during debugging.
Updated Solution (2013):
A simpler approach is to utilize the Error object's stack property:
function stackTrace() { var err = new Error(); return err.stack; }
Das obige ist der detaillierte Inhalt vonWie erhalte ich Stack-Trace-Informationen in JavaScript?. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!