# p-try

> `Start a promise chain

Latest version **3.0.0** (published 2021-10-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install p-try
pnpm add p-try
yarn add p-try
bun add p-try
```

## Health

**Score 38/100 (D)** — status: abandoned.

Positive: has types package; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2021-10-04 |
| First published | 2016-10-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/p-try) |
| Module format | ESM |
| Node | ^12.20.0 \|\| ^14.13.1 \|\| >=16.0.0 |
| Dependencies | 0 |
| Unpacked size | 4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 62 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | promise, try, resolve, function, catch, async, await, promises, settled, ponyfill, polyfill, shim, bluebird |

## Links

- npm: https://www.npmjs.com/package/p-try
- Repository: https://github.com/sindresorhus/p-try
- Homepage: https://github.com/sindresorhus/p-try#readme
- Issues: https://github.com/sindresorhus/p-try/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/p-try

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 3.0.0 (latest) — 2021-10-04
- 2.2.0 — 2019-03-31
- 2.1.0 — 2019-03-18
- 2.0.0 — 2018-06-14
- 1.0.0 — 2016-10-21

## README

# p-try

> Start a promise chain

[How is it useful?](http://cryto.net/~joepie91/blog/2016/05/11/what-is-promise-try-and-why-does-it-matter/)

## Install

```sh
npm install p-try
```

## Usage

```js
import pTry from 'p-try';

try {
	const value = await pTry(() => {
		return synchronousFunctionThatMightThrow();
	});
	console.log(value);
} catch (error) {
	console.error(error);
}
```

## API

### pTry(fn, ...arguments)

Returns a `Promise` resolved with the value of calling `fn(...arguments)`. If the function throws an error, the returned `Promise` will be rejected with that error.

Support for passing arguments on to the `fn` is provided in order to be able to avoid creating unnecessary closures. You probably don't need this optimization unless you're pushing a *lot* of functions.

#### fn

The function to run to start the promise chain.

#### arguments

Arguments to pass to `fn`.

## Related

- [More…](https://github.com/sindresorhus/promise-fun)

---

<div align="center">
	<b>
		<a href="https://tidelift.com/subscription/pkg/npm-p-try?utm_source=npm-p-try&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
	</b>
	<br>
	<sub>
		Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
	</sub>
</div>

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