<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Rethrowing error resets stack trace making debugging hard"
   href="https://bugs.webkit.org/show_bug.cgi?id=167934">167934</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Rethrowing error resets stack trace making debugging hard
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>WebKit
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>Safari 10
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>Normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P2
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>JavaScriptCore
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>webkit-unassigned&#64;lists.webkit.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>malteubl&#64;google.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>In JavaScript it is common to rethrow errors when they cannot immediately be handled. Here is some example code:

try {
  mayThrow();
} catch (e) {
  if (e.message == 'something I can handle') {
    handleError(e);
  } else {
    throw e;
  }
}

When executed in JavaScriptCore the error object created in the try block gets a new stack trace when it is rethrown. While there are situations when that might be desirable in the vast majority of cases it is not. Especially in this common pattern:

try {
  mayThrow();
} catch (e) {
  // Don't interrupt execution flow, but do report error.
  setTimeout(function() {
    throw e;
  });
}

Java solves this my making stack traces a linked list of places an exception haa been thrown. Since this is not available in JS, one must choose, and choosing the original location is better in the vast majority of cases.

Here is a full repro case:
<a href="http://output.jsbin.com/lufeqe/quiet">http://output.jsbin.com/lufeqe/quiet</a>

Compare the console output between V8 and JavaScriptCore. In V8 it is immediately obvious what happened, while JSC provides no useful information for 2 of the 3 errors.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>