ErrorException

(PHP 5 >= 5.1.0, PHP 7, PHP 8)

Einführung

Eine Error-Exception.

Klassenbeschreibung

class ErrorException extends Exception {
/* Eigenschaften */
protected int $severity = E_ERROR;
/* Geerbte Eigenschaften */
protected string $message = "";
private string $string = "";
protected int $code;
protected string $file = "";
protected int $line;
private array $trace = [];
private ?Throwable $previous = null;
/* Methoden */
public __construct(
    string $message = "",
    int $code = 0,
    int $severity = E_ERROR,
    ?string $filename = null,
    ?int $line = null,
    ?Throwable $previous = null
)
final public getSeverity(): int
/* Geerbte Methoden */
final public Exception::getMessage(): string
final public Exception::getCode(): int
final public Exception::getFile(): string
final public Exception::getLine(): int
final public Exception::getTrace(): array
final public Exception::getTraceAsString(): string
public Exception::__toString(): string
private Exception::__clone(): void
}

Eigenschaften

severity

Die Schwere einer Exception

Beispiele

Beispiel #1 Verwenden von set_error_handler() zum Verändern von Fehlermeldungen innerhalb ErrorException.

<?php
function exception_error_handler($severity$message$file$line) {
    if (!(
error_reporting() & $severity)) {
        
// Dieser Fehlercode ist nicht in error_reporting enthalten
        
return;
    }
    throw new 
ErrorException($message0$severity$file$line);
}
set_error_handler("exception_error_handler");

/* Exception ausloesen */
strpos();
?>

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

Fatal error: Uncaught exception 'ErrorException' with message 'strpos() expects at least 2 parameters, 0 given' in /home/bjori/tmp/ex.php:12
Stack trace:
#0 [internal function]: exception_error_handler(2, 'strpos() expect...', '/home/bjori/php...', 12, Array)
#1 /home/bjori/php/cleandocs/test.php(12): strpos()
#2 
  thrown in /home/bjori/tmp/ex.php on line 12

Inhaltsverzeichnis

Hier Kannst Du einen Kommentar verfassen


Bitte gib mindestens 10 Zeichen ein.
Wird geladen... Bitte warte.
* Pflichtangabe
Es sind noch keine Kommentare vorhanden.

Was genau bedeutet "Vibe Coding"? Ein tiefgehender Blick für Entwickler

In der Welt der Softwareentwicklung gibt es unzählige Wege, wie man an ein Projekt herangeht. Manche schwören auf strikte Planung, andere auf bewährte Algorithmen und wieder andere lassen sich von etwas ganz anderem leiten: ihrem Gefühl. ...

admin

Autor : admin
Kategorie: Software & Web-Development

PHP cURL-Tutorial: Verwendung von cURL zum Durchführen von HTTP-Anfragen

cURL ist eine leistungsstarke PHP-Erweiterung, die es Ihnen ermöglicht, mit verschiedenen Servern über verschiedene Protokolle wie HTTP, HTTPS, FTP und mehr zu kommunizieren. ...

TheMax

Autor : TheMax
Kategorie: PHP-Tutorials

Midjourney Tutorial - Anleitung für Anfänger

Über Midjourney, dem Tool zur Erstellung digitaler Bilder mithilfe von künstlicher Intelligenz, gibt es ein informatives Video mit dem Titel "Midjourney Tutorial auf Deutsch - Anleitung für Anfänger" ...

Mike94

Autor : Mike94
Kategorie: KI Tutorials

Tutorial veröffentlichen

Tutorial veröffentlichen

Teile Dein Wissen mit anderen Entwicklern weltweit

Du bist Profi in deinem Bereich und möchtest dein Wissen teilen, dann melde dich jetzt an und teile es mit unserer PHP-Community

mehr erfahren

Tutorial veröffentlichen

Große JSON-Dateien in PHP effizient streamen?

Don’t use json_decode() for GB-scale files. Use a streaming parser (SAX-style) like jsonstreamingparser, or redesign the JSON into newline-delim ...

Geschrieben von jackmarvia689 am 28.01.2026 10:41:56
Forum: PHP Developer Forum
Kalenderwoche auf Sonntag anfangen lassen

The heart of Udaipur is City Palace, a magnificent complex overlooking Lake Pichola. With its balconies, courtyards, and museums, the palace offer ...

Geschrieben von dehradunbite am 28.01.2026 08:48:33
Forum: PHP Developer Forum
Kalenderwoche auf Sonntag anfangen lassen

One of the reasons https://dehradun.sumistajoshi.com​ are gaining popularity is the diversity they offer. Companions often come from different b ...

Geschrieben von dehradunbite am 28.01.2026 08:42:06
Forum: PHP Developer Forum
Provider stellt auf envelope-from um. Was muss ich bei meinem Code ändern?

Wenn der Provider das Envelope-From/Return-Path vorgibt, musst du im Code meist nichts Großes ändern – nur sicherstellen, dass deine Mail-Libr ...

Geschrieben von deviceeditor am 27.01.2026 11:24:00
Forum: PHP Developer Forum