# attempt-statement

> try in fp

Latest version **1.2.1** (published 2025-12-24) · UNLICENSED license · 0 weekly downloads

## Install

```sh
npm install attempt-statement
pnpm add attempt-statement
yarn add attempt-statement
bun add attempt-statement
```

## Health

**Score 45/100 (D)** — status: stable.

Positive: no vulnerabilities.

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

## Facts

| | |
|---|---|
| Version | 1.2.1 |
| Published | 2025-12-24 |
| First published | 2024-08-22 |
| Weekly downloads | 0 |
| License | UNLICENSED |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 2.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | fox |
| Maintainers | tj-commits |
| Keywords | attempt, try, catch, lua, rescue |

## Links

- npm: https://www.npmjs.com/package/attempt-statement
- Repository: https://github.com/in-fp/attempt-statement
- Homepage: https://github.com/in-fp/attempt-statement#readme
- Issues: https://github.com/in-fp/attempt-statement/issues
- npm.io page: https://npm.io/package/attempt-statement

## Dependencies (1)

- [true-value](https://npm.io/package/true-value.md) ^2.0.5

## 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

- 1.2.1 (latest) — 2025-12-24
- 1.2.0 — 2025-12-19
- 1.1.0 — 2024-08-22
- 1.0.0 — 2024-08-22

## README

# attempt-statement
Never use try/catch/finally again, use attempt/rescue/else/ensure instead.

## usage
```javascript
const attempt = require('attempt-statement')
attempt(() => {
  consoe.log('this line throws an error because i mispelled console as consoe')
}).rescue((error) => {
  console.log('Error: ' + error)
}).else(() => {
  console.log('this will never be run because there\'s always an error')
}).ensure(() => {
  console.log('This will always be run')
}).end()
// Output:

// Error: ReferenceError: consoe is not defined
// This will always be run
```
above is equivalent to
```javascript
let error = false
try {
  consoe.log('this line throws an error because i mispelled console as consoe')

  console.log('this will never be run because there\'s always an error')
} catch(error) {
  console.log('Error: ' + error)
  error = true
} finally {
  console.log('This will always be run')
}
// Output:

// Error: ReferenceError: consoe is not defined
// This will always be run
```

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