Error caused by other error

Jordan Harband ljharb at gmail.com
Mon Aug 6 15:41:03 UTC 2018


Stacks themselves aren't yet in the language, see
https://github.com/tc39/proposal-error-stacks.

As for "the stack trace from the caught error", it's lost because you let
`err` go out of scope - if you want to preserve `err.stack`, you have to do
so (with `throw err`, or by saving the information somewhere, like on your
newly created error). Also, stacks are generated at the time the error
object is instantiated, not at the place you `throw`.

On Mon, Aug 6, 2018 at 5:48 AM, Michał Wadas <michalwadas at gmail.com> wrote:

> Was there any proposal to introduce longer stack traces to language?
>
> Eg.
> ```
> try {
> catch Error('foo');
> } catch (err) {
> throw Error('bar'); // stack trace from caught error is lost
> }
> ```
>
>
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180806/b90b7e2c/attachment.html>


More information about the es-discuss mailing list