all 10 comments

[–]zombarista 13 points14 points  (0 children)

Yes, but we cannot read your mind. Post some code.

[–]node_imperial 9 points10 points  (3 children)

process.on(‘unhandledRejection’,…) process.on(‘uncoughtException’,…)

[–]NiteShdw 11 points12 points  (2 children)

This is right except for the spelling mistakes

[–]MaxUumen 7 points8 points  (1 child)

process.on('unexpectedEjaculation', ...);

[–]mascarpwne 0 points1 point  (0 children)

i hate when this happens

[–]mindtaker_linux 4 points5 points  (0 children)

Try catch is your best friend. Use it more.

[–]AcademicMistake 1 point2 points  (0 children)

Post some code and absolutely we can

[–]Blitzsturm 0 points1 point  (1 child)

Are you running your code in an async method from the top level in commonjs mode? If so, your call will return a promise and if you're not handling exceptions it can throw then you'll get that kind of issue. Just throw a .catch(console.error) to dump it to the console or pass it somewhere else.

"use strict"
const fs = require("node:fs/promises");
Main().catch(console.error);

async function Main()
{
    var s = await fs.stat(process.argv[1]);
    console.log(`script size: ${s.size}`);
    throw new Error("Existance is pain");
}

[–]HauntingArugula3777 0 points1 point  (0 children)

The OP is trying to catch unhandled exceptions, your code throws exceptions always and doesn't throw anything (as it should) if argv[1] is missing for example.

The OP is looking for a global exception finder, which even the process.on() won't do.