Start · Sprachen · PHP · Referenz · Exception

Exception

Klasse

Basis-Klasse aller Business-/Domain-Fehler in PHP.

seit PHP 5.0.0 Kategorie: error

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");