1.2.105. Can’t Throw Throwable

Classes extending Throwable can’t be thrown, unless they also extend Exception. The same applies to interfaces that extends Throwable.

Although such code lints, PHP throws a Fatal error when executing or including it : Class fooThrowable cannot implement interface `Throwable <https://www.php.net/manual/en/class.`throwable <https://www.php.net/throwable>`_.php>`_, extend `Exception <https://www.php.net/exception>`_ or `Error <https://www.php.net/error>`_ instead.

<?php

// This is the way to go
class fooException extends \Exception { }

// This is not possible and a lot of work
class fooThrowable implements \throwable { }

?>

See also Throwable, Exception and Error.

1.2.105.1. Suggestions

  • Extends the Exception class

  • Extends the Error class

1.2.105.2. Specs

Short name

Exceptions/CantThrow

Rulesets

All, Analyze, Changed Behavior, LintButWontExec

Exakat since

1.3.3

PHP Version

All

Severity

Minor

Time To Fix

Slow (1 hour)

Precision

Very high

Features

throwable

Note

This issue may lint but will not run

Available in

Entreprise Edition, Exakat Cloud