Skip to content

Domains created inside uncaughtException event handler don't allow catching errors thrown inside the domain.run()Β #22400

@m0uneer

Description

@m0uneer
  • Version: v10.5.0
  • Platform: Linux pc 4.13.0-41-generic # 46~16.04.1-Ubuntu SMP Thu May 3 10:06:43 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
  • Subsystem:
const domain = require('domain');

function captureUncaughtException() {
  const createdDomain = domain.create();
  createdDomain.on('error', () => console.log('Caught error within the domain!'));
  createdDomain.run(notExistingFn);
}

process.on('uncaughtException', captureUncaughtException.bind(this));
throw new Error();

// Expected output:
// Caught error within the domain!

// Actual output:
// ReferenceError: notExistingFn is not defined

And on contrary to the above scenario, if we call captureUncaughtException() directly, it behaves normally.

captureUncaughtException();

// Output:
// Caught error within the domain!

Metadata

Metadata

Assignees

No one assigned

    Labels

    domainIssues and PRs related to the domain subsystem.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions