PHPackages                             krmgns/errorise - 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. krmgns/errorise

ActiveLibrary

krmgns/errorise
===============

An elegant way to handle errors in PHP.

2.0.1(2y ago)05Apache-2.0PHPPHP &gt;=7.4

Since Oct 19Pushed 2y ago1 watchersCompare

[ Source](https://github.com/krmgns/errorise)[ Packagist](https://packagist.org/packages/krmgns/errorise)[ Docs](https://github.com/krmgns/errorise)[ RSS](/packages/krmgns-errorise/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (6)Used By (0)

If you are tired of using the `@` error suppression operator and then digging for errors with the `error_get_last()` function, you can try using Errorise. Errorise offers well-caught PHP errors to handle them on your side, freeing you from these stuff for each error-prone call.

### Installing

[](#installing)

```
composer require krmgns/errorise

```

### Using `ErrorHandler`

[](#using-errorhandler)

```
use Errorise;

$eh = new Errorise\ErrorHandler();
try {
    fopen('/path/to/file.txt', 'r');

    // Throws if any error occured.
    $eh->throw();
} catch (Errorise\ErrorException $e) {
    // Message: fopen(/path/to/file.txt): Failed to open ...
    throw new YourCustomException_After_Some_Business(
        $e->getMessage()
    );
} finally {
    // Trigger handler __destruct() to call unregister().
    unset($eh);
}
```

### Using `ErrorHandler` for Specific Functions / Patterns

[](#using-errorhandler-for-specific-functions--patterns)

You can controll that when to throw or for which function or message pattern to throw.

```
try {
    fopen('/path/to/file.txt', 'r');

    // Throws if any error occured with fopen().
    $eh->throwFor('fopen');

    // Throws if any error occured with message pattern.
    $eh->throwForMatch('/fopen/');
} catch (Errorise\ErrorException $e) {
    // ...
} finally {
    // ...
}
```

### Using `ErrorHandler` for Undefined Variables

[](#using-errorhandler-for-undefined-variables)

Like for function errors, `ErrorHandler` is available for undefined variable errors as well:

```
try {
    $bar = $foo;

    // Throws since $foo is undefined.
    $eh->throw();
} catch (Errorise\ErrorException $e) {
    // ...
} finally {
    // ...
}
```

### Using `ErrorHandler` with Non-Auto Mode

[](#using-errorhandler-with-non-auto-mode)

If you want full controll on register / unregister routine, pass `$auto` argument as `false`, just like:

```
$eh = new Errorise\ErrorHandler(false);
try {
    // Register Errorise error handler.
    $eh->register();

    // Some risky or error-prone works.

    // Throws if any error occured.
    $eh->throw();
} catch (Errorise\ErrorException $e) {
    // ...
} finally {
    // Un-Register Errorise error handler.
    // So, back to the previous or internal error handler.
    $eh->unregister();
}
```

### Getting Error Messages in Catch

[](#getting-error-messages-in-catch)

You can get error messages by using two methods of caught `ErrorException`.

```
try {
    // ...
} catch (Errorise\ErrorException $e) {
    // Message: mkdir(): No such file or directory
    $e->getMessage();

    // Message: No such file or directory
    $e->getPureMessage();
} finally {
    // ...
}
```

### Utilising `Error` Object

[](#utilising-error-object)

To get more details, you can utilise the `$error` property of the `ErrorHandler` which is passed to the caught `ErrorException`.

```
try {
    // ...
} catch (Errorise\ErrorException $e) {
    // @var Errorise\Error
    $error = $e->error();

    // Data: [severity, message, file, line]
    $data = $error->data();

    // Severity: 2
    $error->getSeverity();

    // Message: mkdir(): No such file or directory
    $error->getMessage();

    // File: /tmp/php/errorise/test.php
    $error->getFile();

    // Line: 3, where mkdir() was called.
    $error->getLine();

    // Function / Variable Name.
    $error->getFunction();
    $error->getVariable();
} finally {
    // ...
}
```

### Using `ErrorWrapper`

[](#using-errorwrapper)

You can use `ErrorWrapper` to wrap your calls instead of using try/catch blocks.

```
$ret = Errorise\ErrorWrapper::wrap(function () {
    $fp = fopen('/path/to/file.txt', 'r');
    return $fp;
}, $e /* byref */);

assert($ret == false);
assert($e instanceof Errorise\ErrorException);
```

### Manually Handling the Last Errors

[](#manually-handling-the-last-errors)

You can use `LastErrorException` to throw errors after checking your call results.

```
use Errorise;

// Your filesystem module.
class FileSystem {
    public static function createDirectory(
        string $dir, int $mode = 0777, bool $recursive = false
    ): void {
        $ok = @mkdir($dir, $mode, $recursive);
        if (!$ok) {
            throw new Errorise\LastErrorException();
        }
    }
}

// Your client layer.
try {
    FileSystem::createDirectory('/tmp');
} catch (Errorise\LastErrorException $e) {
    // Message: mkdir(): File exists
    throw new YourCustomException_After_Some_Business(
        $e->getMessage()
    );
}
```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

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

Total

5

Last Release

842d ago

Major Versions

1.0.2 → 2.0.02022-10-22

PHP version history (3 changes)1.0.0PHP ^7.4

1.0.1PHP ~7.4

1.0.2PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/70f9bcd96f92716abf051f22448ab55da368441dbc3e1d96bcebd70e132dcc59?d=identicon)[krmgns](/maintainers/krmgns)

---

Top Contributors

[![krmgns](https://avatars.githubusercontent.com/u/1508306?v=4)](https://github.com/krmgns "krmgns (46 commits)")

---

Tags

errorerror handling

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/krmgns-errorise/health.svg)

```
[![Health](https://phpackages.com/badges/krmgns-errorise/health.svg)](https://phpackages.com/packages/krmgns-errorise)
```

###  Alternatives

[filp/whoops

php error handling for cool kids

13.2k402.4M1.4k](/packages/filp-whoops)[nunomaduro/collision

Cli error handling for console/command-line PHP applications.

4.6k331.8M8.5k](/packages/nunomaduro-collision)[facade/ignition

A beautiful error page for Laravel applications.

2.1k102.2M333](/packages/facade-ignition)[spatie/laravel-ignition

A beautiful error page for Laravel applications.

566146.7M471](/packages/spatie-laravel-ignition)[spatie/ignition

A beautiful error page for PHP applications.

510147.6M69](/packages/spatie-ignition)

PHPackages © 2026

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