Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It isn't perfect, but I found a partial solution.</p> <p>Fact 1: <code>Error.prototype</code> is an Error object.</p> <p>Fact 2: The method <code>Error.prototype.toString</code> is called whenever an error is created.</p> <p>Fact 3: The field <code>Error.prototype.toString</code> can be modified.</p> <p>That method typically just returns the string "Error", so we can replace it with our own method that stores the stack and then returns the string "Error".</p> <pre class="lang-js prettyprint-override"><code>Error.prototype.toString = function() { if (typeof this.stack === "undefined" || this.stack === null) { this.stack = "placeholder"; // The previous line is needed because the next line may indirectly call this method. this.stack = $.stack; } return "Error"; } try { throw new Error("Houston, we have a problem."); } catch (e) { $.writeln("Line: " + e.line); $.writeln("File: " + e.fileName); $.writeln("Message: " + e.message); $.writeln("Stack: " + e.stack); } </code></pre> <p>Result:</p> <pre><code>Line: 11 File: ~/Desktop/Source10.jsx Message: Houston, we have a problem. Stack: [Source10.jsx] toString() </code></pre> <p>It works! The only problem is automatic errors.</p> <pre class="lang-js prettyprint-override"><code>Error.prototype.toString = function() { if (typeof this.stack === "undefined" || this.stack === null) { this.stack = "placeholder"; // The previous line is needed because the next line may indirectly call this method. this.stack = $.stack; } return "Error"; } try { var foo = null; foo.bar; } catch (e) { $.writeln("Line: " + e.line); $.writeln("File: " + e.fileName); $.writeln("Message: " + e.message); $.writeln("Stack: " + e.stack); } </code></pre> <p>Result:</p> <pre><code>Line: 12 File: ~/Desktop/Source12.jsx Message: null is not an object Stack: undefined </code></pre> <p>So it doesn't work on all errors, but its progress.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload