Skip to content

REPL cannot evaluate try/catch #9

Description

@MarcelloDuarte

try/catch/finally is not implemented, so any error handling typed into the REPL fails outright.

phunkie > try { throw new RuntimeException("boom"); } catch (Exception $e) { echo $e->getMessage(); }
Error: Evaluation error: Unsupported statement type: PhpParser\Node\Stmt\TryCatch

evaluateAst() has no Node\Stmt\TryCatch branch, so it falls through to the catch-all at src/Functions/evaluation.php:286.

This is probably the most valuable of the missing statement types: exception handling is ordinary PHP that users will reach for constantly, and throw already works (features/repl/throw_expressions.feature), which makes the gap more surprising — you can throw but not catch.

It also blocks acceptance coverage for a PHP 8.5 change: a missing trait became a catchable Error rather than a fatal, which can only be demonstrated with try/catch.

Needs TryCatch and Finally_ branches, covering multi-catch (catch (A|B $e)), catch without a variable (catch (Exception)), finally running on both paths, and rethrow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions