Signatur
class Exception implements Throwable
Beschreibung
Für vorhersehbare Fehler-Zustände. Immer eine passendere Sub-Klasse wählen (RuntimeException, InvalidArgumentException, ...).
Parameter
| Name | Typ | Default | Beschreibung |
|---|---|---|---|
| $message | string | "" | Fehler-Nachricht. |
| $code | int | 0 | Fehler-Code. |
| $previous | ?Throwable | null | Verkette Exception. |
Rückgabewert
Typ
Exception
Beschreibung
Neue Instanz.
Beispiele
Custom Exception
<?php
final class ProductNotFoundException extends \RuntimeException {}
throw new ProductNotFoundException("Produkt {$id} nicht gefunden");