rethrowing exceptions
On May 20, 2014, at 1:10 PM, John Lenz wrote:
Has there been any discussion about rethrowing exceptions such that they retain the original context?
try { throws(); } catch (e) { if (e instanceof SomeError) { // handle it } rethrow e; }
Or is this been out side the spec because stack traces in general are outside the spec?
It isn't really clear if "throw e;" should have the original stack trace or a new stack trace attached due to the throw.
Yes, there is no concept of exception context or of a captured stack trace in the ES specification so there really isn't any difference between throwing and rethrowing an exception. If we ever decide to standardize the capture of exception contexts then we will need to such issues. Arguably, this is one of the barriers to standardizing such capture. There is baggage that comes with it that any serious proposal needs to take into account.
Has there been any discussion about rethrowing exceptions such that they retain the original context?
try { throws(); } catch (e) { if (e instanceof SomeError) { // handle it } rethrow e; }
Or is this been out side the spec because stack traces in general are outside the spec?
It isn't really clear if "throw e;" should have the original stack trace or a new stack trace attached due to the throw.