# Parse Errors

> 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/>

Wrong Syntax leads to parse errors and PHP unceremoniously aborts the execution. This is not particularly surprising as there is not really much else for PHP to do if it can’t understand the given code.

As mentioned earlier there is nothing you can do in PHP 5 to recover but registering a shutdown handler at least allows for a controlled termination. For that to work, of course, the parse error must not have occurred in the initially loaded script but in a file included or required.

With PHP 7 and Engine Exceptions the shutdown handler is no longer required. In the case of a parse error, a `ParseError` will be thrown, getting all relevant information along – like filename, line number, and the actual error. A `ParseError`, as any `Error`, can be handled using a `try` / `catch` block:

``` php
try {
    require '_syntax_error.php';
} catch (ParseError $parseError) {
    var_dump($parseError);
}
```

If a `ParseError` is not caught, it will translate back into a classic PHP error and will terminate the process.

---

Previous: [Engine Exceptions](https://php7explained.com/new-and-extended-functionality/error-handling/engine-exceptions/index.html.md) | Next: [Parse Errors in evaluated Code](https://php7explained.com/new-and-extended-functionality/error-handling/parse-errors-in-evaluated-code/index.html.md)
