PHPackages                             eatae/throwable-instruction - 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. [Debugging &amp; Profiling](/categories/debugging)
4. /
5. eatae/throwable-instruction

ActiveLibrary[Debugging &amp; Profiling](/categories/debugging)

eatae/throwable-instruction
===========================

Exception instructions

1.0.0(2y ago)15[1 issues](https://github.com/eatae/throwable-instruction/issues)GPL-3.0-onlyPHPPHP &gt;=7.4

Since Apr 29Pushed 2y ago1 watchersCompare

[ Source](https://github.com/eatae/throwable-instruction)[ Packagist](https://packagist.org/packages/eatae/throwable-instruction)[ RSS](/packages/eatae-throwable-instruction/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (7)Used By (0)

Throwable instruction
=====================

[](#throwable-instruction)

 **A PHP library for creating Exception Instructions**

 [![Source Code](https://camo.githubusercontent.com/752d2c541079afa12457619d3e23bb90a89fdc29387d234b48c16fe013973a61/687474703a2f2f696d672e736869656c64732e696f2f62616467652f736f757263652d65617461652f7468726f7761626c65e28093696e737472756374696f6e2d2f3f636f6c6f723d343638324234)](https://github.com/eatae/throwable-instruction) [![Download Package](https://camo.githubusercontent.com/e0818aa1a464c995b29a1eb98862f84bcf5bb81020b89c574902de89f7fa57b2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f65617461652f7468726f7761626c652d696e737472756374696f6e3f636f6c6f723d266c6162656c3d72656c65617365)](https://packagist.org/packages/eatae/throwable-instruction) [![PHP Programming Language](https://camo.githubusercontent.com/618187df65f6cbfe9af4fe59b704bc50d64dcbce1824a8f3775d20a9b3c537a3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f65617461652f7468726f7761626c652d696e737472756374696f6e3f636f6c6f723d393337304442)](https://php.net) [![GitHub License](https://camo.githubusercontent.com/602dc722a5bb7b856248b21b9aa627602b1da8f331746583fd7b6b753f02f4db/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f65617461652f7468726f7761626c652d696e737472756374696f6e3f636f6c6f723d394143443332)](https://github.com)

Description
-----------

[](#description)

**Throwable Instruction** makes it possible to define additional actions when an Exception is thrown in a specific place.

### Translation

[](#translation)

[RU](https://github.com/eatae/throwable-instruction/blob/develop/docs/_RU-README.md)

Simple example
--------------

[](#simple-example)

#### Call а instruction for the specified Exception type

[](#call-а-instruction-for-the-specified-exception-type)

```
try {
    $instruction = new ThrowableInstruction();
    $operation = new EchoOperation('Some output.');
    /*
     * Throwing an exception with an instruction
     */
    throw new LogicException('Some message.', 0, $instruction->add($operation));
} catch (LogicException $e) {
    echo $e->getMessage();
    /*
     * Call instructions for a specified exception
     */
    Operator::followInstruction($e);
}
```

#### Calling an instruction for any type of Exception

[](#calling-an-instruction-for-any-type-of-exception)

```
try {
    $instruction = new ThrowableInstruction();
    $operation = new EchoOperation('Some output.');
    /*
     * Throwing an exception with an instruction
     */
    throw new LogicException('Some message.', 0, $instruction->add($operation));
} catch (LogicException $e) {
    echo $e->getMessage();
} finally {
    /*
     * Call instructions for all exceptions
     */
    if (isset($e) && is_subclass_of($e, Exception::class)) {
        Operator::followInstruction($e);
    }
}
```

Usage
-----

[](#usage)

1. **Create an operation class**

```
class ImportantMessageOperation implements OperationInterface
{
    protected string $message;
    protected int $code;

    public function __construct(string $message, int $code)
    {
        $this->message = $message;
        $this->code = $code;
    }

    public function execute(): void
    {
        echo "Important: {$this->message}. Code: {$this->code}";
    }
}
```

2. **Call the Operator::followInstruction() method**

```
public function whereExceptionsAreCaught(): void
{
    $object = new \stdClass();
    try {
        /*
         * Some code...
         */
        $this->item->doSomethingElse($object, $this->validator, $this->instruction);
    } catch (Exception $e) {
        $this->logger->log($e->getMessage(), $e->getCode());
    } finally {
        /*
         * Call instructions for all exceptions
         */
        if (isset($e) && is_subclass_of($e, Exception::class)) {
            Operator::followInstruction($e);
        }
    }
}
```

3. **Provide instructions for Exception**

- No instructions

```
public function doSomething(object $entity): void
{
    if (!$this->validator->validate($entity)) {
        /*
         *  InvalidArgumentException without instructions
         */
        throw new InvalidArgumentException('Entity is not valid object');
    }
}
```

- With Notice instructions

```
public function doSomethingElse(object $item): void
{
    if (!$this->validator->validate($item)) {
        /*
         * InvalidArgumentException with Notice instructions
         */
        throw new InvalidArgumentException(
            'Item is not valid object',
            0,
            $this->instruction->operation(NoticeMessageOperation::class, ['Invalid values passed'])
        );
    }
}
```

- With Important and CriticalEmail instructions

```
public function doSomethingImportant(object $importantItem): void
{
    if (!$this->validator->validate($importantItem)) {
        /*
         * InvalidArgumentException with Important instructions
         */
        throw new InvalidArgumentException(
            'Important Item is not valid object',
            0,
            $this->instruction
                ->operation(ImportantMessageOperation::class, ['Important values are not valid', 500])
                ->operation(SendCriticalEmailOperation::class, ['Any message text'])
        );
    }
}
```

Conclusion
----------

[](#conclusion)

Try/catch in different places in the code or the lack of a logical hierarchy of Exceptions can make them difficult to work with. Throwable Instruction will not fix architectural problems, but it may improve understanding of the actions caused by Exceptions and add the ability to reuse these actions.

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

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 ~300 days

Total

3

Last Release

876d ago

Major Versions

0.1.1 → 1.0.02023-12-20

### Community

Maintainers

![](https://www.gravatar.com/avatar/6439c35c26305ff284fc6463ca4dfae526dcdf3a996807a515dc216eb73129aa?d=identicon)[eatae](/maintainers/eatae)

---

Top Contributors

[![eatae](https://avatars.githubusercontent.com/u/19387668?v=4)](https://github.com/eatae "eatae (15 commits)")

---

Tags

exceptionphp

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/eatae-throwable-instruction/health.svg)

```
[![Health](https://phpackages.com/badges/eatae-throwable-instruction/health.svg)](https://phpackages.com/packages/eatae-throwable-instruction)
```

###  Alternatives

[symfony/stopwatch

Provides a way to profile code

2.8k387.2M918](/packages/symfony-stopwatch)[fruitcake/laravel-debugbar

PHP Debugbar integration for Laravel

19.1k662.9k29](/packages/fruitcake-laravel-debugbar)[spatie/ignition

A beautiful error page for PHP applications.

510147.6M69](/packages/spatie-ignition)[jokkedk/webgrind

Webgrind is a Xdebug profiling web frontend in PHP5. It implements a subset of the features of kcachegrind and installs in seconds and works on all platforms. For quick'n'dirty optimizations it does the job.

3.3k193.0k](/packages/jokkedk-webgrind)[koriym/printo

An object graph visualizer.

1421.8M2](/packages/koriym-printo)[soloterm/dumps

A Laravel command to intercept dumps from your Laravel application.

125285.7k3](/packages/soloterm-dumps)

PHPackages © 2026

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