# @zhaoyao91/try-catch

> Return result and error instead of throwing.

Latest version **0.0.0** (published 2019-09-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install @zhaoyao91/try-catch
pnpm add @zhaoyao91/try-catch
yarn add @zhaoyao91/try-catch
bun add @zhaoyao91/try-catch
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.0 |
| Published | 2019-09-07 |
| First published | 2019-09-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 2.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | zhaoyao91 |
| Maintainers | zhaoyao91 |
| Keywords | try, catch, try-catch |

## Links

- npm: https://www.npmjs.com/package/@zhaoyao91/try-catch
- npm.io page: https://npm.io/package/@zhaoyao91/try-catch

## Alternatives

- [@sentry/react-native](https://npm.io/package/@sentry/react-native.md) — 2.6M weekly downloads
- [@ardatan/aggregate-error](https://npm.io/package/@ardatan/aggregate-error.md) — 708.1K weekly downloads
- [custom-error-generator](https://npm.io/package/custom-error-generator.md) — 2.0K weekly downloads
- [@technik-sde/prosemirror-recreate-transform](https://npm.io/package/@technik-sde/prosemirror-recreate-transform.md) — 1.5K weekly downloads
- [@suchipi/error-utils](https://npm.io/package/@suchipi/error-utils.md) — 78 weekly downloads

## Recent versions

- 0.0.0 (latest) — 2019-09-07

## README

# Try Catch

Return result and error instead of throwing.

## Installation

```bash
npm i @zhaoyao91/try-catch
```

## Usage

### handle sync function

```js
const tryCatch = require("@zhaoyao91/try-catch");

function fn(...args) {
  // throw or return
}

const [error, result] = tryCatch(fn, ...args);
```

### handle async function

```js
const tryCatch = require("@zhaoyao91/try-catch");

async function fn(...args) {
  // throw or return
}

const [error, result] = await tryCatch(fn, ...args);
```

### Customize promise judge logic

```js
require("@zhaoyao91/try-catch").isPromise = function(x) {
  // customized logic to tell if x is a promise
};
```

## License

MIT

---
_Source: https://npm.io/package/@zhaoyao91/try-catch · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
