DenoDDeno
Powered by
Captain 𝗕𝗘𝗘𝗙🥩C
Deno•3y ago•
7 replies
Captain 𝗕𝗘𝗘𝗙🥩

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");
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)
❯ 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
catch
statement isn't running, but the code after the catch statement is executed. And yet the program crashes due to an uncaught error.
Deno banner
DenoJoin
Chat about Deno, a modern runtime for JavaScript and TypeScript.
20,944Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

mkdirsync is throwing an exception that can't be caught?
StokestackSStokestack / help
2y ago
Why happen this...?
VladimirVVladimir / help
2y ago
deno cache isn't working from vscode
shultz🇮🇱Sshultz🇮🇱 / help
3y ago
Why isn't the API_PORT variable being loaded? Is there something I'm missing?
Hermes AlvesHHermes Alves / help
2y ago