Why isn't this error caught?

Basic code example:
try {
  Deno.remove("fakefile");
} catch (err) {
  console.log("File doesn't exist...");
}

console.log("That file didn't exist");


The output when you run this is the following:
❯ deno run -A delete.js
That file didn't exist
error: Uncaught (in promise) NotFound: No such file or directory (os error 2), remove 'fakefile'
    at async Object.remove (ext:deno_fs/30_fs.js:175:3)


So the code within the
catch
statement isn't running, but the code after the catch statement is executed. And yet the program crashes due to an uncaught error.
Was this page helpful?