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

Engine Exceptions — Error Hierarchy (PHP 7.0)

php PHP 7.0+ Intermediate

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 21
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
2 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 1 ping F 0 pings S 0 pings S 1 ping M 0 pings T 0 pings W 0 pings T 2 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 1 ping T 1 ping 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
No pings yet today
Amazonbot 1
Amazonbot 10 Unknown AI 3 Google 2 Perplexity 2 ChatGPT 1 Ahrefs 1
crawler 16 crawler_json 1 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