Field Manual PHP / Laravel reference
← PHP

Exceptions

Exceptions interrupt execution until caught; Throwable covers Error and Exception.

What it is

Exceptions interrupt execution until caught; Throwable covers Error and Exception.

When to use it

Signal unexpected failure and translate it at an appropriate boundary.

Syntax

try {
    // operation
} catch (Throwable $e) {
    // handle or rethrow
}

Example

try {
    $data = json_decode($input, true, 512, JSON_THROW_ON_ERROR);
} catch (JsonException $e) {
    throw new InvalidArgumentException("Malformed JSON", previous: $e);
}

Common mistakes

Do not silently swallow Throwable or expose stack traces to clients.

Related topics

Exceptions