# Parse Errors in `eval`uated Code

> Section in “New and Extended Functionality › Error Handling” of the book [PHP 7 Explained](https://php7explained.com/) by Sebastian Bergmann and Stefan Priebsch, published by thePHP.cc. The book covers PHP 7.0 to 7.4 and was last updated in November 2020. HTML version: <https://php7explained.com/new-and-extended-functionality/error-handling/parse-errors-in-evaluated-code/>

Even though the need for `eval()` usually points out a design flaw, PHP’s handling of parse errors in evaluated code has been improved in PHP 7.

A parse error encountered in code that is to be executed via `eval()` will throw a `ParseError`, exactly like PHP would do for included or required code.

``` php
try {
    eval('parse error');
    echo 'next in line';
} catch (ParseError $parseError) {
    var_dump($parseError);
}
```

The main difference compared to included code is that PHP 5 continued to run even if the execution of the `eval()` failed. Since PHP 7 throws a `ParseError`, the line containing the `echo` statement in the example above will never be reached. If that line were to do some error handling or logging, you would need to adjust it for PHP 7 by moving that line into the `catch` block.

---

Previous: [Parse Errors](https://php7explained.com/new-and-extended-functionality/error-handling/parse-errors/index.html.md) | Next: [Recoverable Fatal Errors](https://php7explained.com/new-and-extended-functionality/error-handling/recoverable-fatal-errors/index.html.md)
