class ExceptionHandler

ExceptionHandler converts an exception to a Response object.

It is mostly useful in debug mode to replace the default PHP/XDebug output with something prettier and more useful.

As this class is mainly used during Kernel boot, where nothing is yet available, the Response content is always HTML.

Methods

__construct($debug = true, $charset = 'UTF-8')

No description

register(Boolean $debug = true)

Registers the exception handler.

handle(Exception $exception)

Sends a response for the given Exception.

sendPhpResponse(Exception|FlattenException $exception)

Sends the error associated with the given Exception as a plain PHP response.

createResponse(Exception|FlattenException $exception)

Creates the error Response associated with the given Exception.

string
getContent(FlattenException $exception)

Gets the HTML content associated with the given exception.

string
getStylesheet(FlattenException $exception)

Gets the stylesheet associated with the given exception.

Details

at line line 37
__construct($debug = true, $charset = 'UTF-8')

Parameters

$debug
$charset

at line line 50
static ExceptionHandler register(Boolean $debug = true)

Registers the exception handler.

Parameters

Boolean $debug

Return Value

ExceptionHandler The registered exception handler

at line line 71
handle(Exception $exception)

Sends a response for the given Exception.

If you have the Symfony HttpFoundation component installed, this method will use it to create and send the response. If not, it will fallback to plain PHP functions.

Parameters

Exception $exception An \Exception instance

See also

sendPhpResponse
createResponse

at line line 88
sendPhpResponse(Exception|FlattenException $exception)

Sends the error associated with the given Exception as a plain PHP response.

This method uses plain PHP functions like header() and echo to output the response.

Parameters

Exception|FlattenException $exception An \Exception instance

at line line 109
Response createResponse(Exception|FlattenException $exception)

Creates the error Response associated with the given Exception.

Parameters

Exception|FlattenException $exception An \Exception instance

Return Value

Response A Response instance

at line line 125
string getContent(FlattenException $exception)

Gets the HTML content associated with the given exception.

Parameters

FlattenException $exception A FlattenException instance

Return Value

string The content as a string

at line line 196
string getStylesheet(FlattenException $exception)

Gets the stylesheet associated with the given exception.

Parameters

FlattenException $exception A FlattenException instance

Return Value

string The stylesheet as a string