class ErrorHandler

Error handler.

Properties

protected Container $container Container.
protected bool $disableShutdownHandler Is the shutdown handler disabled?
protected array $handlers Exception handlers.
protected LoggerInterface $logger Logger instance.
protected array $dontLog Exception types that shouldn't be logged.

Methods

__construct(Container|null $container = null)

Constructor.

bool
displayErrors()

Should errors be displayed?

write(string $output)

Write to output.

getFallbackHandler()

Returns the fallback handler.

register()

Registers the exception handler.

setLogger(Closure|LoggerInterface $logger)

Set logger instance or closure that returns a logger instance.

LoggerInterface
getLogger()

Return logger instance.

dontLog(string|array $exceptionType)

Disables logging for an exception type.

disableLoggingFor(string|array $exceptionType) deprecated

Disables logging for an exception type.

disableShutdownHandler()

Disables the shutdown handler.

handle(string $exceptionType, string|Closure $handler)

Prepends an exception handler to the stack.

clearHandlers(string $exceptionType)

Clears all error handlers for an exception type.

replaceHandlers(string $exceptionType, Closure $handler)

Replaces all error handlers for an exception type with a new one.

clearOutputBuffers()

Clear output buffers.

bool
shouldExceptionBeLogged(Throwable $exception)

Should the exception be logged?

handlerFactory(string $handler)

Creates and returns an error handler instance.

mixed
handleException(string|Closure $handler, Throwable $exception)

Handle the exception.

handler(Throwable $exception)

Handles uncaught exceptions.

Details

at line 80
__construct(Container|null $container = null)

Constructor.

Parameters

Container|null $container Container

at line 98
protected bool displayErrors()

Should errors be displayed?

Return Value

bool

at line 115
protected write(string $output)

Write to output.

Parameters

string $output String to write to output

at line 132
protected Closure getFallbackHandler()

Returns the fallback handler.

Return Value

Closure

at line 148
protected register()

Registers the exception handler.

at line 172
setLogger(Closure|LoggerInterface $logger)

Set logger instance or closure that returns a logger instance.

Parameters

Closure|LoggerInterface $logger Logger

at line 182
LoggerInterface getLogger()

Return logger instance.

Return Value

LoggerInterface

at line 197
dontLog(string|array $exceptionType)

Disables logging for an exception type.

Parameters

string|array $exceptionType Exception type or array of exception types

at line 208
disableLoggingFor(string|array $exceptionType) deprecated

deprecated 7.0

Disables logging for an exception type.

Parameters

string|array $exceptionType Exception type or array of exception types

at line 216
disableShutdownHandler()

Disables the shutdown handler.

at line 227
handle(string $exceptionType, string|Closure $handler)

Prepends an exception handler to the stack.

Parameters

string $exceptionType Exception type
string|Closure $handler Exception handler

at line 237
clearHandlers(string $exceptionType)

Clears all error handlers for an exception type.

Parameters

string $exceptionType Exception type

at line 254
replaceHandlers(string $exceptionType, Closure $handler)

Replaces all error handlers for an exception type with a new one.

Parameters

string $exceptionType Exception type
Closure $handler Exception handler

at line 264
protected clearOutputBuffers()

Clear output buffers.

at line 275
protected bool shouldExceptionBeLogged(Throwable $exception)

Should the exception be logged?

Parameters

Throwable $exception An exception object

Return Value

bool

at line 299
protected HandlerInterface handlerFactory(string $handler)

Creates and returns an error handler instance.

Parameters

string $handler Handler class name

Return Value

HandlerInterface

at line 311
protected mixed handleException(string|Closure $handler, Throwable $exception)

Handle the exception.

Parameters

string|Closure $handler Exception handler
Throwable $exception Exceotion

Return Value

mixed

at line 326
handler(Throwable $exception)

Handles uncaught exceptions.

Parameters

Throwable $exception An exception object