Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Cannot throw objects that do not implement Throwable

Description

All classes that are thrown must implement the interfave Throwable. It is possible to catch Throwable objects, but in fact, it is not possible to implement Throwable in a class: this is done by extending either Exception or Error, which, in turn, implements Throwable.

Example

<?php

class X {}

throw new X();

?>

Alternatives

  • Make the class extends \Exception.
  • Make the class extends \Error.
  • Do not throw the class.