Error, TypeError, SyntaxError, RangeError — plus a handful of
APIs that reject with plain strings.
Permission failures are ordinary Error objects with extra properties:
name is PermissionDenied and code is PERMISSION_DENIED. There is no
PermissionDenied constructor, so check e.code rather than using
instanceof.
Uncaught errors
An exception that escapes your script prints the message and stack to stderr, then the process exits 1:Error: Error: prefix, the at <eval> frame carrying
file:line:column, and the blank line before the shell prompt.
try / catch works as usual — for the APIs listed below.
What throws (and what doesn’t)
Syncfsswallows I/O errors today. A missing file, a bad directory, an unreadable path — all returnundefinedwith no exception. Always checkfs.exists()first, or use the Promise variants, which report the real error:
Unhandled promise rejections are silent
In script context a rejected Promise with no handler prints nothing and the process exits 0:.catch, or await inside a try. In an HTTP handler the
runtime does catch it — a rejected handler Promise becomes a 500
response.
fetch rejects with strings
Failed fetches reject with a string, not an Error, so e.message is
undefined:
- The initial
fetchcheck throws anErrornamedPermissionDeniedwithcode: "PERMISSION_DENIED"before the request is submitted. In anasyncfunction that surfaces as a rejected promise. - A denial on a redirect hop rejects the fetch promise with a plain string:
PermissionDenied: fetch requires --allow-net. That string has no.messageand no.code.
Server-side failures
A permission denial is not a handler failure:
http.serve checks its bind scope
when the server starts, and fs / fetch denials inside a handler are thrown
as normal JavaScript exceptions (uncaught → 500).
Exit codes
Message catalogue
Strings you’ll see in practice — useful for assertions in tests:Gotchas
e.messageisundefinedfor ordinaryfetchrejections and redirect permission denials — checktypeof e. Initial permission errors are realErrorobjects.- A successful
fs.*Asynccall hangs the process afterwards (it prints, then never exits) — Known issue, see fs. - Sync
fsI/O failures are silent; don’t writetry/catcharound them expecting an exception. Permission denials do throw. process.envnever throws; a disallowed variable is justundefined.- There is no
PermissionDeniedconstructor — checke.codeore.name. - FFI denials are
PermissionDeniedtoo; the message is bare (ffi.read requires --allow-ffi) because there is no scope. - There is no
process.on("uncaughtException")and nounhandledRejectionhook — there’s nothing to subscribe to. - Errors thrown inside a
Workersurface on the parent viaonerror.