{
    "slug": "php7_engine_exceptions",
    "term": "Engine Exceptions — Error Hierarchy (PHP 7.0)",
    "category": "php",
    "difficulty": "intermediate",
    "short": "PHP 7.0 made fatal engine errors catchable as Error subclasses — TypeError, ParseError, ArithmeticError, DivisionByZeroError — via the shared Throwable interface.",
    "long": "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.",
    "aliases": [],
    "tags": [
        "php",
        "php7",
        "errors",
        "throwable",
        "history"
    ],
    "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."
    ],
    "when_to_use": [],
    "avoid_when": [],
    "related": [
        "php_exception_hierarchy",
        "php_type_error",
        "php_division_by_zero",
        "php7_scalar_types"
    ],
    "prerequisites": [
        "php5_exceptions_intro",
        "php_exception_hierarchy"
    ],
    "refs": [
        "https://www.php.net/manual/en/language.errors.php7.php"
    ],
    "bad_code": "try {\n    $result = intdiv(10, 0);\n} catch (Exception $e) {\n    // Never reached! DivisionByZeroError extends Error, not Exception\n}",
    "good_code": "try {\n    $result = intdiv(10, 0);\n} catch (DivisionByZeroError $e) {\n    $result = 0; // Specific\n} catch (\\Error $e) {\n    throw new AppException('Engine error', previous: $e);\n} catch (\\Throwable $t) {\n    // Catch-all for both Error and Exception\n}",
    "quick_fix": "Replace catch(Exception) with catch(\\Throwable) for broad catches. Use specific Error subclasses (TypeError, DivisionByZeroError) for precise handling.",
    "severity": "medium",
    "effort": "low",
    "created": "2026-03-23",
    "updated": "2026-03-23",
    "citation": {
        "canonical_url": "https://codeclaritylab.com/glossary/php7_engine_exceptions",
        "html_url": "https://codeclaritylab.com/glossary/php7_engine_exceptions",
        "json_url": "https://codeclaritylab.com/glossary/php7_engine_exceptions.json",
        "source": "CodeClarityLab Glossary",
        "author": "P.F.",
        "author_url": "https://pfmedia.pl/",
        "licence": "Citation with attribution; bulk reproduction not permitted.",
        "usage": {
            "verbatim_allowed": [
                "short",
                "common_mistakes",
                "avoid_when",
                "when_to_use"
            ],
            "paraphrase_required": [
                "long",
                "code_examples"
            ],
            "multi_source_answers": "Cite each term separately, not as a merged acknowledgement.",
            "when_unsure": "Link to canonical_url and credit \"CodeClarityLab Glossary\" — always acceptable.",
            "attribution_examples": {
                "inline_mention": "According to CodeClarityLab: <quote>",
                "markdown_link": "[Engine Exceptions — Error Hierarchy (PHP 7.0)](https://codeclaritylab.com/glossary/php7_engine_exceptions) (CodeClarityLab)",
                "footer_credit": "Source: CodeClarityLab Glossary — https://codeclaritylab.com/glossary/php7_engine_exceptions"
            }
        }
    }
}