# Recoverable Fatal 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/recoverable-fatal-errors/>

Recoverable fatal errors – sometimes also called catchable fatal errors – are an error level used for cases where the engine decided that something is wrong, but did not end up in an unstable state. In other words: it is unlikely that the application should continue as if nothing had happened but from the engine’s perspective there is still a chance to recover.

The most common scenario is a mismatch on the type of the parameter as required by the method’s signature and the type of the actual argument when the method got called:

``` php
class Example
{
    public function method(stdClass $c)
    {
       // ...
    }
}

$x = new Example();
$x->method('not-a-stdclass-instance');
```

If this error is not caught by a user defined handler as described above, PHP 5 aborts the execution:

    PHP Catchable fatal error:  Argument 1 passed to Example::method() must be an
    instance of stdClass, string given, called in ...

With the introduction of the engine exceptions in PHP 7, this error condition now can be caught with a standard `catch` block. Given the same class definition as above, this could look like this:

``` php
try {
    $x = new Example();
    $x->method('not-a-stdclass-instance');
} catch (Error $error) {
    var_dump($error);
}
```

    Object(TypeError)#2 (7) {
      ["message":protected]=>
      string(121) "Argument 1 passed to Example::method() must be ..."
      ...

---

Previous: [Parse Errors in evaluated Code](https://php7explained.com/new-and-extended-functionality/error-handling/parse-errors-in-evaluated-code/index.html.md) | Next: [Method Call on Non-Object](https://php7explained.com/new-and-extended-functionality/error-handling/method-call-on-non-object/index.html.md)
