New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@el3um4s/to-try

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@el3um4s/to-try

Wrapper for error handling without try-catch

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
537
increased by205.11%
Maintainers
1
Weekly downloads
 
Created
Source

To Try

Wrapper for error handling without try-catch

Based on:

Install and use the package

To use the package in a project:

npm i @el3um4s/to-try

and then in a file:

import { toTry, toTryAsync } from "@el3um4s/to-try";

// Without a custom error handler
const [result, error] = toTry(() => myThrowableMethod());

// With a custom error handler
const [res, err] = toTry(
  () => myThrowableMethod(),
  error => {
    console.log(error);
  }
);

// Handle methods that return a Promise without a custom error handler
const [res2, err2] = await toTryAsync(() => myAsyncThrowableMethod());

// Handle methods that return a Promise with a custom error handler
const [res3, err3] = await toTryAsync(
  () => myAsyncThrowableMethod(),
  error => {
    console.log(error);
  }
);

// Use result
if (error || err || err2 || err3) {
  // Show error alert
}

sendMyResultToMethod(result);

Keywords

FAQs

Package last updated on 28 Sep 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc