Example with a Function Returning Data
import { withTryCatch } from "@aissadev1/with-try-catch"; function returnData(): string { return "This is the data"; } const result = await withTryCatch(returnData); if (result.error) { console.error("Error:", result.error.message); } else { console.log("Data:", result.data); // Output: "This is the data" }
Example with a Function Throwing an Error
import { withTryCatch } from "@aissadev1/with-try-catch"; function throwError(): string { throw new Error("This is an error"); } const result = await withTryCatch(throwError); if (result.error) { console.error("Error:", result.error.message); // Output: "This is an error" } else { console.log("Data:", result.data); }
Add the package using JSR:
deno add jsr:@aissadev1/with-try-catch
or
npx jsr add @aissadev1/with-try-catch
import { withTryCatch } from "@aissadev1/with-try-catch";
Add Package
deno add jsr:@aissadev1/with-try-catch
Import symbol
import * as with_try_catch from "@aissadev1/with-try-catch";
---- OR ----
Import directly with a jsr specifier
import * as with_try_catch from "jsr:@aissadev1/with-try-catch";
Add Package
npx jsr add @aissadev1/with-try-catch
Import symbol
import * as with_try_catch from "@aissadev1/with-try-catch";
Add Package
yarn dlx jsr add @aissadev1/with-try-catch
Import symbol
import * as with_try_catch from "@aissadev1/with-try-catch";
Add Package
pnpm dlx jsr add @aissadev1/with-try-catch
Import symbol
import * as with_try_catch from "@aissadev1/with-try-catch";
Add Package
bunx jsr add @aissadev1/with-try-catch
Import symbol
import * as with_try_catch from "@aissadev1/with-try-catch";