ErrorException
(PHP 5 >= 5.1.0, PHP 7, PHP 8)
소개
오류 예외.
클래스 개요
class ErrorException extends Exception {
/* Properties */
protected int $severity;
/* Inherited properties */
protected string $message;
protected int $code;
protected string $file;
protected int $line;
/* Methods */
public __construct(
string $message = "",
int $code = 0,
int $severity = E_ERROR,
?string $filename = null,
?int $line = null,
?Throwable $previous = null
)
final public getSeverity(): int
/* Inherited methods */
final public Exception::getMessage(): string
final public Exception::getPrevious(): ?Throwable
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
final private Exception::__clone(): void
}
속성(Properties)
- severity
- 예외의 심각도
Examples
예제 #1 오류 메시지를 ErrorException으로 변경하려면 set_error_handler()를 사용하십시오.
<?php
function exception_error_handler($severity, $message, $file, $line) {
if (!(error_reporting() & $severity)) {
// This error code is not included in error_reporting
return;
}
throw new ErrorException($message, 0, $severity, $file, $line);
}
set_error_handler("exception_error_handler");
/* Trigger exception */
strpos();
?>
위의 예는 다음과 유사한 결과를 출력합니다.
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 {main} thrown in /home/bjori/tmp/ex.php on line 12
목차
- ErrorException::__construct — Constructs the exception
- ErrorException::getSeverity — Gets the exception severity