Skip to content

Instantly share code, notes, and snippets.

@zen0wu
Created July 7, 2019 04:32
Show Gist options
  • Select an option

  • Save zen0wu/c30b9f7a6a868741eac1ec7f5ab37f09 to your computer and use it in GitHub Desktop.

Select an option

Save zen0wu/c30b9f7a6a868741eac1ec7f5ab37f09 to your computer and use it in GitHub Desktop.

Revisions

  1. zen0wu created this gist Jul 7, 2019.
    29 changes: 29 additions & 0 deletions test.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    function errorPromise() {
    return new Promise((_resolve, _reject) => {
    console.log('error coming up');
    throw new Error('oops');
    });
    }

    function okPromise() {
    return new Promise((_resolve, _reject) => {
    console.log('ok');
    // _resolve('ok');
    setTimeout(() => _resolve('ok'), 0);
    });
    }

    async function cannotCatchError() {
    try {
    const p = okPromise();
    const p2 = errorPromise();
    // await Promise.all([p, p2]);
    await p;
    await p2;
    } catch (e) {
    console.log('caught', e);
    }
    console.log('done');
    }

    cannotCatchError();