← Home ← Codex ← DEBT
Browse by Category
+ added · updated 7d
← Back to glossary

Engine Exceptions — Error Hierarchy (PHP 7.0)

PHP PHP 7.0+ Intermediate
debt(d5/e1/b3/t7)
d5 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'specialist tool catches it' (d5). The detection_hints list phpstan and psalm as the tools that catch the pattern `catch.*(Exception` — these are static analysis tools that require deliberate setup, not default linters or compilers. The mistake is invisible at runtime until an Error (e.g. TypeError) is thrown and silently escapes an Exception-only catch block.

e1 Effort Remediation debt — work required to fix once spotted

Closest to 'one-line patch or single-call swap' (e1). The quick_fix is explicit: replace `catch(Exception)` with `catch(\Throwable)` — a single-line change per catch site. Even for precise handling, swapping to a specific Error subclass is a minimal local edit.

b3 Burden Structural debt — long-term weight of choosing wrong

Closest to 'localised tax' (b3). The concept applies across web, cli, and queue-worker contexts, but the fix is localized to each catch block. It doesn't reshape architecture or slow many work streams — it's a per-catch-site concern that affects only developers writing or reviewing error handling code.

t7 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'serious trap' (t7). The misconception is explicit: developers familiar with PHP 5 or other languages naturally expect `catch (Exception $e)` to catch all thrown things, but in PHP 7 the Error hierarchy is completely separate from Exception. This directly contradicts how exception hierarchies work in most other languages and in PHP 5, making it a serious cross-language/cross-version trap.

About DEBT scoring →

TL;DR

PHP 7.0 made fatal engine errors catchable as Error subclasses — TypeError, ParseError, ArithmeticError, DivisionByZeroError — via the shared Throwable interface.

Explanation

PHP 7.0 introduced the Error class (distinct from Exception) implementing Throwable. Engine errors that previously caused uncatchable fatals now throw Error subclasses: ParseError (eval syntax errors), TypeError (type declaration violations), ArithmeticError / DivisionByZeroError (math errors), AssertionError (assert() failures), Error (generic engine errors). catch (\Throwable $t) catches everything. catch (\Error $e) catches engine errors only. This unified PHP's error handling — no more register_shutdown_function() to detect fatal errors that were actually TypeError.

Common Misconception

catch (Exception $e) catches PHP 7 engine errors — it doesn't. TypeError, ParseError etc. extend Error not Exception. Use catch (\Throwable $t) for both.

Why It Matters

PHP 7 engine exceptions transformed PHP error handling — previously fatal errors now have a recovery path via catch, enabling more resilient applications.

Common Mistakes

  • Catching Exception when TypeError/Error should also be caught.
  • Not knowing that each Error subclass can be caught specifically.
  • Missing the Throwable interface — it's what unifies Error and Exception.

Code Examples

✗ Vulnerable
try {
    $result = intdiv(10, 0);
} catch (Exception $e) {
    // Never reached! DivisionByZeroError extends Error, not Exception
}
✓ Fixed
try {
    $result = intdiv(10, 0);
} catch (DivisionByZeroError $e) {
    $result = 0; // Specific
} catch (\Error $e) {
    throw new AppException('Engine error', previous: $e);
} catch (\Throwable $t) {
    // Catch-all for both Error and Exception
}

Added 23 Mar 2026
Views 45
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 1 ping W 1 ping T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 2 pings F 0 pings S 0 pings S 1 ping M 1 ping T 0 pings W 0 pings T 2 pings F 0 pings S 0 pings S 0 pings M 0 pings T 2 pings W 0 pings T 0 pings F 0 pings S 0 pings S 1 ping M 0 pings T 0 pings W
No pings yet today
No pings yesterday
Amazonbot 10 Google 4 Scrapy 4 Unknown AI 3 Ahrefs 3 Perplexity 2 Claude 2 SEMrush 2 ChatGPT 1 Bing 1 Meta AI 1 PetalBot 1
crawler 29 crawler_json 3 pre-tracking 2
DEV INTEL Tools & Severity
🟡 Medium ⚙ Fix effort: Low
⚡ Quick Fix
Replace catch(Exception) with catch(\Throwable) for broad catches. Use specific Error subclasses (TypeError, DivisionByZeroError) for precise handling.
📦 Applies To
PHP 7.0+ web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
catch.*\(Exception
Auto-detectable: ✓ Yes phpstan psalm
⚠ Related Problems
🤖 AI Agent
Confidence: High False Positives: Medium ✓ Auto-fixable Fix: Low Context: Function Tests: Update
CWE-390 CWE-755


✓ schema.org compliant