PHPackages                             transprime-research/attempt - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. transprime-research/attempt

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

transprime-research/attempt
===========================

A fluent helper for object-oriented style of try-catch statements

2.0.0(2y ago)417[3 issues](https://github.com/transprime-research/attempt/issues)MITPHPPHP &gt;=7.4CI failing

Since May 7Pushed 2y ago1 watchersCompare

[ Source](https://github.com/transprime-research/attempt)[ Packagist](https://packagist.org/packages/transprime-research/attempt)[ Docs](https://omitobi.github.io/transprime-research/attempt/)[ RSS](/packages/transprime-research-attempt/feed)WikiDiscussions master Synced today

READMEChangelog (3)Dependencies (3)Versions (4)Used By (0)

[![](https://github.com/transprime-research/assets/raw/master/attempt/twitter_header_photo_2.png)](https://github.com/transprime-research/assets/blob/master/attempt/twitter_header_photo_2.png)

[ ![Build Status](https://camo.githubusercontent.com/5ba10a31bbae233bb13696fc7ab02388aa9840c12fd623cce487e2eed022d79c/68747470733a2f2f7472617669732d63692e6f72672f7472616e737072696d652d72657365617263682f617474656d70742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/transprime-research/attempt)[ ![Latest Stable Version](https://camo.githubusercontent.com/5b6d0b0c676244836593f71b194398db479caaa66bbc924528cb281cfbcaaca7/68747470733a2f2f706f7365722e707567782e6f72672f7472616e737072696d652d72657365617263682f617474656d70742f762f737461626c65)](https://packagist.org/packages/transprime-research/attempt)[ ![Total Downloads](https://camo.githubusercontent.com/096e3f0962215c6a665dafb4d2eee44c55290d3fad7282999ad2c85127bcd65a/68747470733a2f2f706f7365722e707567782e6f72672f7472616e737072696d652d72657365617263682f617474656d70742f646f776e6c6f616473)](https://packagist.org/packages/transprime-research/attempt)[ ![Latest Unstable Version](https://camo.githubusercontent.com/be443ea9dd4edc8da433f2524d5a6f8bf9f9900e984681a20c789467a8e4c616/68747470733a2f2f706f7365722e707567782e6f72672f7472616e737072696d652d72657365617263682f617474656d70742f762f756e737461626c65)](https://packagist.org/packages/transprime-research/attempt)[ ![Latest Monthly Downloads](https://camo.githubusercontent.com/5132d5a3a5d4cccf41f1494bdeab03451f8f688b1bd3e4487cca7d9f57ace93c/68747470733a2f2f706f7365722e707567782e6f72672f7472616e737072696d652d72657365617263682f617474656d70742f642f6d6f6e74686c79)](https://packagist.org/packages/transprime-research/attempt) [ ![License](https://camo.githubusercontent.com/da3d60b2166bda5eee5035c3863b885e3097ecb87bae4a847622a6984bb21c2c/68747470733a2f2f706f7365722e707567782e6f72672f7472616e737072696d652d72657365617263682f617474656d70742f6c6963656e7365)](https://packagist.org/packages/transprime-research/attempt)

About Attempt
-------------

[](#about-attempt)

Try and catch in php objected oriented way

> Do It like a pro 🆗

Usage
-----

[](#usage)

```
$response = attempt(fn() => $this->client->get('ninja'))
    ->catch(ConnectException::class)
    ->done(fn() => []); //done can be replaced with ()
```

Installation:
-------------

[](#installation)

Minimum requirement is PHP 7.2+ and Composer.

Install with this:

```
composer require transprime-research/attempt
```

Other usage:
------------

[](#other-usage)

```
$response = Attempt::on(fn() => $this->client->get('ninja'))
    ->catch(AttemptTestException::class)(); // or ->done()

// Do something with Response
```

`catch` method accepts an Exception object:

```
$response = Attempt::on(fn() => $this->client->get('ninja'))
    ->catch(\AttemptTestException())(); // or ->done()

// Do something with Response
```

Set a default response:

```
$response = Attempt::on(fn() => $this->client->get('ninja'))
    ->with(['abc'])
    ->catch(AttemptTestException::class)
    ->done(); // ['abc'] is returned if exception is caught
```

```
// with default value
attempt(fn() => $this->execute())
    ->catch(AttemptTestException::class, 'It is done') //returns 'It is done'
    ->done();

// closure as default value
attempt(fn() => $this->execute())
    ->catch(AttemptTestException::class, fn() => 'It is done') //returns 'It is done'
    ->done();

// handle the resolved default value in done()
attempt(fn() => $this->execute())
    ->catch(AttemptTestException::class, fn() => 'error') //returns 'It is done'
    ->done(fn(Exception $ex, $severity) => logger($severity, $ex));
```

Multiple Exception

```
$response = Attempt::on(fn() => $this->client->get('ninja'))
    ->catch(AttemptTestException::class, HttpResponseException::class)()

// Do something with Response
```

Multiple Catch block

```
attempt(fn() => $this->execute())
    ->catch(NinjaException::class, 'Ninja error') //returns 'It is done')
    ->catch(AnotherExeption::class, 'Another error') //returns 'It is done'
    ->done(fn($ex) => logger()->error($ex));
```

Do more with the caught Exception response:

```
$response = Attempt::on(fn() => $this->client->get('ninja'))
    ->catch(AttemptTestException::class, HttpResponseException::class)
    ->done(fn(\HttpResponseException $e) => logger()->error($e->getMessage()));

// Do something with Response
```

More to come: Pass the execution of a default value to a callable Class

```
// loading...
```

Additional Information
----------------------

[](#additional-information)

This package is part of a series of "The Code Dare".

See other packages in this series here:

-  \[Smart Piping in PHP\]
-  \[A smarter Array now like an object\]
-  \[A smart PHP if...elseif...else statement\]
-  \[A smart Carbon + Collection package\]
-  \[Jsonable Http Request(er) package with Collections response\]

Similar packages
----------------

[](#similar-packages)

- TBA

Licence
-------

[](#licence)

MIT (See LICENCE file)

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance5

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~727 days

Total

3

Last Release

793d ago

Major Versions

1.1.0 → 2.0.02024-04-30

PHP version history (2 changes)1.0.0PHP &gt;=7.2

2.0.0PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/364011bafbabff7b8c66b670b16ae372944dd4cc555531affffd901aae53d297?d=identicon)[omitobisam](/maintainers/omitobisam)

---

Top Contributors

[![omitobi](https://avatars.githubusercontent.com/u/16482234?v=4)](https://github.com/omitobi "omitobi (44 commits)")

---

Tags

phptrycatchlaravelhelpersattempttry and catch

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/transprime-research-attempt/health.svg)

```
[![Health](https://phpackages.com/badges/transprime-research-attempt/health.svg)](https://phpackages.com/packages/transprime-research-attempt)
```

###  Alternatives

[rappasoft/laravel-helpers

Laravel Helpers for Non-Laravel Projects

277681.9k22](/packages/rappasoft-laravel-helpers)[devmarketer/easynav

Making managing navigation in Laravel easy.

105160.5k](/packages/devmarketer-easynav)[transprime-research/piper

PHP Pipe method execution with values from chained method executions

174.7k2](/packages/transprime-research-piper)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
