D
Deno

help

Why isn't this error caught?

CCaptainBeefPanties3/22/2023
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 statement isn't running, but the code after the catch statement is executed. And yet the program crashes due to an uncaught error.
UUUnknown User3/22/2023
Message Not Public
Sign In & Join Server To View
CCaptainBeefPanties3/22/2023
Interesting, I'll give this a try. Thanks!
DDoctor3/22/2023
You don’t need to handle it like this. You just need to await it within the try catch. Not awaiting it will let the try catch continue down and out, not catching any errors that the promise may throw.
// this will only throw an error if the fetch function fails to return a promise.
try {
return fetch()
} catch {}

// this will catch any errors the promise will throw as well as if it fails to return a promise.
try {
return await fetch()
} catch {}
// this will only throw an error if the fetch function fails to return a promise.
try {
return fetch()
} catch {}

// this will catch any errors the promise will throw as well as if it fails to return a promise.
try {
return await fetch()
} catch {}
Basically where the promise is being resolved is where the errors from the promise will be thrown and caught.
UUUnknown User3/23/2023
Message Not Public
Sign In & Join Server To View

Looking for more? Join the community!

Recommended Posts
Using dynamic import with npm compatibility gives intermittent error "__DENO_NODE_GLOBAL_THIS_167935This is pretty hard to google because the number at the end of the error changes everytime it happenGraphql codegendoes anyone have a solution to generate the sdk using graphq-request with Deno?Deno Third Party Modules Web HooksIs there a way to see the webhook payload URL a package you have published is listening for?Does Deno Deploy support location based analytics?The free version does not seem to support it. Does the paid version support it?IPC solution for a process manager👋 I'm at day 7 of working on Pup (https://github.com/hexagon/pup) - a universal process manager rSpecifying config remotely or jsx on installI'm struggling quite a lot here. I originally recommended using this command: ```bash deno install -Is it possible to know what version of a dynamically-imported module was just imported?Right now, you can run code like `import('npm:lodash')`, which will get the latest version of lodashWhy am I getting an "Uncaught DOM Exception" in the Deno CLI?To replicate: 1. `deno` in the command line to initialize a Deno REPL ``` // Get an array of random Better way to allow downloading of files besides serving entire fileI'm trying to allow users to download files that are in a private folder which cannot be accessed puShare state between islandsHi. How could I share state between island. E.g. shopping cart. I click on add product and in some oIslands not working with Cloudflare DNS proxyI have deployed Deno on a remote server with nginx-ingress-controller that offers self-signed certifUpdate sub-directory for module already added to deno.land/xThe title pretty much says it all, but the module in question is `hot_mod`, and the current subdir iShould we, or how should we, use Deno as a sandbox for untrusted code?I've been using Deno in this context because of some of the nice security model features. However, ideno_bindgen type error: deno-ts(2345)Anyone else getting this with `deno_bindgen`? > Argument of type 'bigint' is not assignable to paramUsing Rust FFI in a public Deno moduleI'm writing a Deno module that I intend to publish on deno.land. It will be using a Rust library (puPublishing to deno.land/x: GitHub webhook says it's delivered?I followed these directions (https://deno.land/add_module) to publish a 3rd party module to deno.lan