thesis/exceptionally

Thesis Exceptionally

Maintainers

Package info

github.com/thesis-php/exceptionally

pkg:composer/thesis/exceptionally

Fund package maintenance!

www.tinkoff.ru/cf/5MqZQas2dk7

Statistics

Installs: 383

Dependents: 1

Suggesters: 0

Stars: 5

Open Issues: 0

0.3.0 2026-03-30 14:51 UTC

This package is auto-updated.

Last update: 2026-03-30 15:53:36 UTC


README

A tiny PHP library that converts errors to exceptions.

Installation

composer require thesis/exceptionally

Requires PHP 8.3+.

Usage

use function Thesis\exceptionally;

// Converts PHP errors to ErrorException
$content = exceptionally(static fn() => file_get_contents('/path/to/file'));

Many PHP functions trigger errors instead of throwing exceptions. This makes error handling inconsistent and cumbersome. exceptionally() wraps a callable and converts any triggered error into a native ErrorException.

Error suppression operator

Errors suppressed with @ are not converted to exceptions:

// Does not throw — the error is suppressed
$content = exceptionally(static fn() => @file_get_contents('/path/to/file'));

Filtering by error level

By default, all levels except E_DEPRECATED and E_USER_DEPRECATED are converted. Deprecations typically come from third-party libraries and should not interrupt execution.

You can specify which levels to convert:

// Convert notices
$result = exceptionally($function, E_USER_NOTICE);

// Convert warnings and notices
$result = exceptionally($function, E_USER_WARNING | E_USER_NOTICE);

// Convert all, including deprecations
$result = exceptionally($function, E_ALL);

License

MIT