|
1 | 1 | <!DOCTYPE html> |
2 | 2 | <html> |
3 | | - <head> |
4 | | - <meta charset="UTF-8" /> |
| 3 | +<head> |
| 4 | + <meta charset="UTF-8"/> |
5 | 5 | <title>Exception Lab</title> |
6 | 6 | <style> |
7 | | - #info { |
8 | | - height: 25em; |
9 | | - width: 100%; |
10 | | - } |
| 7 | + #info { |
| 8 | + height: 25em; |
| 9 | + width: 100%; |
| 10 | + } |
11 | 11 | </style> |
12 | 12 | <script src="../../stacktrace.js"></script> |
13 | 13 | <script src="ExceptionLab.js"></script> |
14 | 14 | <script> |
15 | | - var lastException; |
| 15 | + var lastException; |
16 | 16 |
|
17 | | - function dumpStacktrace(guess) { |
18 | | - var trace = printStackTrace({ |
19 | | - e: lastException, |
20 | | - guess: guess |
21 | | - }); |
22 | | - var text = trace.join("\n\n"); |
23 | | - document.getElementById("info").innerHTML = text; |
24 | | - } |
| 17 | + function info(text) { |
| 18 | + document.getElementById("info").innerHTML = text; |
| 19 | + } |
25 | 20 |
|
26 | | - function dumpException(ex) { |
27 | | - ex = ex || new Error("Default error"); |
28 | | - var text = "{\n " + getExceptionProps(ex).join(",\n ") + "\n}"; |
29 | | - document.getElementById("info").innerHTML = text; |
30 | | - lastException = ex; |
31 | | - } |
| 21 | + function dumpStacktrace(guess) { |
| 22 | + var trace = printStackTrace({ |
| 23 | + e: lastException, |
| 24 | + guess: guess |
| 25 | + }); |
| 26 | + info(trace.join("\n\n")); |
| 27 | + } |
32 | 28 |
|
33 | | - function dumpException1() { |
34 | | - dumpException(); |
35 | | - } |
| 29 | + function dumpException(ex) { |
| 30 | + ex = ex || new Error("Default error"); |
| 31 | + var text = "{\n " + getExceptionProps(ex).join(",\n ") + "\n}"; |
| 32 | + info(text); |
| 33 | + lastException = ex; |
| 34 | + } |
36 | 35 |
|
37 | | - function dumpException2() { |
38 | | - try { |
39 | | - undef(); |
40 | | - } catch (ex) { |
41 | | - dumpException(ex); |
| 36 | + function dumpException1() { |
| 37 | + dumpException(); |
42 | 38 | } |
43 | | - } |
44 | 39 |
|
45 | | - function dumpException3() { |
46 | | - dumpException((function(x) { |
47 | | - try { |
48 | | - x.undef(); |
49 | | - } catch (ex) { |
50 | | - return ex; |
51 | | - } |
52 | | - })(null)); |
53 | | - } |
| 40 | + function dumpException2() { |
| 41 | + try { |
| 42 | + undef(); |
| 43 | + } catch (ex) { |
| 44 | + dumpException(ex); |
| 45 | + } |
| 46 | + } |
54 | 47 |
|
55 | | - function createException4() { |
56 | | - return createException(); |
57 | | - } |
| 48 | + function dumpException3() { |
| 49 | + dumpException((function(x) { |
| 50 | + try { |
| 51 | + x.undef(); |
| 52 | + } catch (ex) { |
| 53 | + return ex; |
| 54 | + } |
| 55 | + })(null)); |
| 56 | + } |
58 | 57 |
|
59 | | - function dumpException4() { |
60 | | - dumpException(createException4()); |
61 | | - } |
| 58 | + function createException4() { |
| 59 | + return createException(); |
| 60 | + } |
62 | 61 |
|
63 | | - function dumpException5() { |
64 | | - try { |
65 | | - //eval("x.undef()"); |
66 | | - eval("getExceptionProps()"); |
67 | | - } catch (ex) { |
68 | | - dumpException(ex); |
| 62 | + function dumpException4() { |
| 63 | + dumpException(createException4()); |
| 64 | + } |
| 65 | + |
| 66 | + function dumpException5() { |
| 67 | + try { |
| 68 | + //eval("x.undef()"); |
| 69 | + eval("getExceptionProps()"); |
| 70 | + } catch (ex) { |
| 71 | + dumpException(ex); |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + function dumpException6() { |
| 76 | + var fn = function() { |
| 77 | + return { |
| 78 | + name: "provide multi-line source in exception" |
| 79 | + }; |
| 80 | + }; |
| 81 | + try { |
| 82 | + fn.nonExistentMethod(); |
| 83 | + } catch (ex) { |
| 84 | + dumpException(ex); |
| 85 | + } |
69 | 86 | } |
70 | | - } |
71 | | - </script> |
72 | | - </head> |
73 | | - <body> |
74 | | - <span id="userAgent">userAgent</span> |
75 | | - <script> |
76 | | - document.getElementById("userAgent").innerHTML = navigator.userAgent; |
77 | 87 | </script> |
78 | | - <textarea id="info">Info</textarea> |
79 | | - <br/> |
80 | | - <button onclick="dumpException1();">Exception 1</button> |
81 | | - <button onclick="dumpException2();">Exception 2</button> |
82 | | - <button onclick="dumpException3();">Exception 3</button> |
83 | | - <button onclick="dumpException4();">Exception 4</button> |
84 | | - <button onclick="dumpException5();">Exception 5</button> |
85 | | - <br/> |
86 | | - <button onclick="dumpStacktrace();">Process stack trace</button> |
87 | | - <button onclick="dumpStacktrace(true);">Guess anonymous functions</button> |
88 | | - </body> |
| 88 | +</head> |
| 89 | +<body> |
| 90 | +<span id="userAgent">userAgent</span> |
| 91 | +<script> |
| 92 | + document.getElementById("userAgent").innerHTML = navigator.userAgent; |
| 93 | +</script> |
| 94 | +<textarea id="info">Info</textarea> |
| 95 | +<br/> |
| 96 | +<button onclick="dumpException1();">Exception 1</button> |
| 97 | +<button onclick="dumpException2();">Exception 2</button> |
| 98 | +<button onclick="dumpException3();">Exception 3</button> |
| 99 | +<button onclick="dumpException4();">Exception 4</button> |
| 100 | +<button onclick="dumpException5();">Exception 5</button> |
| 101 | +<button onclick="dumpException6();">Exception 6</button> |
| 102 | +<br/> |
| 103 | +<button onclick="dumpStacktrace();">Process stack trace</button> |
| 104 | +<button onclick="dumpStacktrace(true);">Guess anonymous functions</button> |
| 105 | +</body> |
89 | 106 | </html> |
0 commit comments