Field Manual PHP / Laravel reference
← Engineering

Error handling

Error handling distinguishes invalid input, conflicts, and unexpected failure.

What it is

Error handling distinguishes invalid input, conflicts, and unexpected failure.

When to use it

Preserve invariants and translate failures at boundaries.

Syntax

Invalid input -> 422
Forbidden -> 403
State conflict -> 409
Unexpected -> 500 + private report

Example

try {
    $result = $operation->run($input);
} catch (BusinessConflict $e) {
    return response()->json(["error" => "conflict"], 409);
}

Common mistakes

Swallowing exceptions can commit partial operations; retry only when semantics allow it.

Related topics

Null handlingError responsesSecure error handling