W3cubDocs

/Symfony 2.7

Symfony\Component\Debug\ExceptionHandler

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, $fileLinkFormat = null)
static ExceptionHandler register($debug = true, $fileLinkFormat = null)

Registers the exception handler.

callable|null setHandler(callable $handler)

Sets a user exception handler.

string setFileLinkFormat(string $format)

Sets the format for links to source files.

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.

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.

catchOutput($buffer)
cleanOutput($buffer)

Details

public __construct($debug = true, $fileLinkFormat = null)

Parameters

$debug
$fileLinkFormat

static public ExceptionHandler register($debug = true, $fileLinkFormat = null)

Registers the exception handler.

Parameters

$debug
$fileLinkFormat

Return Value

ExceptionHandler The registered exception handler

public callable|null setHandler(callable $handler)

Sets a user exception handler.

Parameters

callable $handler An handler that will be called on Exception

Return Value

callable|null The previous exception handler if any

public string setFileLinkFormat(string $format)

Sets the format for links to source files.

Parameters

string $format The format for links to source files

Return Value

string The previous file link format.

public handle(Exception $exception)

Sends a response for the given Exception.

To be as fail-safe as possible, the exception is first handled by our simple exception handler, then by the user exception handler. The latter takes precedence and any output from the former is cancelled, if and only if nothing bad happens in this handling path.

Parameters

Exception $exception

public 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

public 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

public 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

public 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

public catchOutput($buffer)

Parameters

$buffer

public cleanOutput($buffer)

Parameters

$buffer

© 2004–2016 Fabien Potencier
Licensed under the MIT License.
http://api.symfony.com/2.7/Symfony/Component/Debug/ExceptionHandler.html