<html> <head> <script type="text/javascript"> function printStackTrace() { var callstack = []; var isCallstackPopulated = false; try { i.dont.exist+=0; //does not exist - that's the point } catch(e) { if (e.stack) { //Firefox var lines = e.stack.split("\n"); for (var i = 0, len = lines.length; i < len; i++) { if (lines[i].match(/^\s*[A-Za-z0-9\-_\$]+\(/)) { callstack.push(lines[i]); } } //Remove call to printStackTrace() callstack.shift(); isCallstackPopulated = true; } else if (window.opera && e.message) { //Opera var lines = e.message.split("\n"); for (var i = 0, len = lines.length; i < len; i++) { if (lines[i].match(/^\s*[A-Za-z0-9\-_\$]+\(/)) { var entry = lines[i]; //Append next line also since it has the file info if (lines[i+1]) { entry += " at " + lines[i+1]; i++; } callstack.push(entry); } } //Remove call to printStackTrace() callstack.shift(); isCallstackPopulated = true; } } if (!isCallstackPopulated) { //IE and Safari var currentFunction = arguments.callee.caller; while (currentFunction) { var fn = currentFunction.toString(); //If we can't get the function name set to "anonymous" var fname = fn.substring(fn.indexOf("function") + 8, fn.indexOf("(")) || "anonymous"; callstack.push(fname); currentFunction = currentFunction.caller; } } output(callstack); } function output(arr) { //Optput however you want alert(arr.join("\n\n")); } </script> </head> <script type="text/javascript"> function foo() { var blah; bar("blah"); } function bar(blah) { var stuff; thing(); } function thing() { if (true) { //your error condition here printStackTrace(); } } foo(); </script> </body> </html>
'코드' 카테고리의 다른 글
prototype 1.6에서 SelectBOX 생성 (0) | 2009.03.07 |
---|---|
ServletFilter를 통한 URI 재구성 (Blog처럼) (1) | 2009.02.22 |
DoCapture(IHTMLElement *ele, IViewObject2 *vObj, int width, int height, int cwidth, int cheight, int wd, int hd) (0) | 2008.08.19 |
TShellWindows (0) | 2008.08.19 |
TInternetExplorer (0) | 2008.08.14 |