class JError

Error Handling Class

This class is inspired in design and concept by patErrorManager http://www.php-tools.net

patErrorManager contributors include: - gERD Schaufelberger gerd@php-tools.net - Sebastian Mordziol argh@php-tools.net - Stephan Schmidt scst@php-tools.net

Properties

static boolean $legacy Legacy error handling marker

Methods

static  boolean
isError( mixed $object)

Method to determine if a value is an exception object.

static  JException|boolean
getError( boolean $unset = false)

Method for retrieving the last exception object in the error stack

static  JException[]
getErrors()

Method for retrieving the exception stack

static  void
addToStack( JException $e)

Method to add non-JError thrown JExceptions to the JError stack for debugging purposes

static  JException
raise( integer $level, string $code, string $msg, mixed $info = null, boolean $backtrace = false)

Create a new JException object given the passed arguments

static  JException
throwError( JException $exception)

Throw an error

static  JException
raiseError( string $code, string $msg, mixed $info = null)

Wrapper method for the raise() method with predefined error level of E_ERROR and backtrace set to true.

static  JException
raiseWarning( string $code, string $msg, mixed $info = null)

Wrapper method for the {@link raise()} method with predefined error level of E_WARNING and backtrace set to false.

static  JException
raiseNotice( string $code, string $msg, mixed $info = null)

Wrapper method for the {@link raise()} method with predefined error level of E_NOTICE and backtrace set to false.

static  array
getErrorHandling( integer $level)

Method to get the current error handler settings for a specified error level.

static  boolean|JException
setErrorHandling( integer $level, string $mode, mixed $options = null)

Method to set the way the JError will handle different error levels. Use this if you want to override the default settings.

static  void
attachHandler()

Method that attaches the error handler to JError

static  void
detachHandler()

Method that detaches the error handler from JError

static  boolean
registerErrorLevel( integer $level, string $name, string $handler = 'ignore')

Method to register a new error level for handling errors

static  string|boolean
translateErrorLevel( integer $level)

Translate an error level integer to a human readable string e.g. E_ERROR will be translated to 'Error'

static  JException
handleIgnore( JException $error, array $options)

Ignore error handler - Ignores the error

static  JException
handleEcho( JException $error, array $options)

Echo error handler - Echos the error message to output

static  JException
handleVerbose( JException $error, array $options)

Verbose error handler - Echos the error message to output as well as related info

static  void
handleDie( JException $error, array $options)

Die error handler - Echos the error message to output and then dies

static  JException
handleMessage( JException $error, array $options)

Message error handler Enqueues the error message into the system queue

static  JException
handleLog( JException $error, array $options)

Log error handler Logs the error message to a system log file

static  JException
handleCallback( JException $error, array $options)

Callback error handler - Send the error object to a callback method for error handling

static  void
customErrorPage( JException $error)

Display a custom error page and exit gracefully

static  void
customErrorHandler( integer $level, string $msg)

Display a message to the user

static  string
renderBacktrace( Exception $error)

Render the backtrace

Details

static boolean isError( mixed $object)

Method to determine if a value is an exception object.

Parameters

mixed $object Object to check.

Return Value

boolean True if argument is an exception, false otherwise.

static JException|boolean getError( boolean $unset = false)

Method for retrieving the last exception object in the error stack

Parameters

boolean $unset True to remove the error from the stack.

Return Value

JException|boolean Last JException object in the error stack or boolean false if none exist

static JException[] getErrors()

Method for retrieving the exception stack

Return Value

JException[] Chronological array of errors that have been stored during script execution

static void addToStack( JException $e)

Method to add non-JError thrown JExceptions to the JError stack for debugging purposes

Parameters

JException $e Add an exception to the stack.

Return Value

void

static JException raise( integer $level, string $code, string $msg, mixed $info = null, boolean $backtrace = false)

Create a new JException object given the passed arguments

Parameters

integer $level The error level - use any of PHP's own error levels for this: EERROR, EWARNING, ENOTICE, EUSERERROR, EUSERWARNING, EUSER_NOTICE.
string $code The application-internal error code for this error
string $msg The error message, which may also be shown the user if need be.
mixed $info Optional: Additional error information (usually only developer-relevant information that the user should never see, like a database DSN).
boolean $backtrace Add a stack backtrace to the exception.

Return Value

JException

See also

JException

static JException throwError( JException $exception)

Throw an error

Parameters

JException $exception &$exception An exception to throw.

Return Value

JException A reference to the handled JException object

See also

JException

static JException raiseError( string $code, string $msg, mixed $info = null)

Wrapper method for the raise() method with predefined error level of E_ERROR and backtrace set to true.

Parameters

string $code The application-internal error code for this error
string $msg The error message, which may also be shown the user if need be.
mixed $info Optional: Additional error information (usually only developer-relevant information that the user should never see, like a database DSN).

Return Value

JException $error The thrown JException object

See also

JError::raise()

static JException raiseWarning( string $code, string $msg, mixed $info = null)

Wrapper method for the {@link raise()} method with predefined error level of E_WARNING and backtrace set to false.

Parameters

string $code The application-internal error code for this error
string $msg The error message, which may also be shown the user if need be.
mixed $info Optional: Additional error information (usually only developer-relevant information that the user should never see, like a database DSN).

Return Value

JException $error The thrown JException object

See also

JError::raise()

static JException raiseNotice( string $code, string $msg, mixed $info = null)

Wrapper method for the {@link raise()} method with predefined error level of E_NOTICE and backtrace set to false.

Parameters

string $code The application-internal error code for this error
string $msg The error message, which may also be shown the user if need be.
mixed $info Optional: Additional error information (usually only developer-relevant information that the user should never see, like a database DSN).

Return Value

JException $error The thrown JException object

See also

JError::raise()

static array getErrorHandling( integer $level)

Method to get the current error handler settings for a specified error level.

Parameters

integer $level The error level to retrieve. This can be any of PHP's own error levels, e.g. EALL, ENOTICE...

Return Value

array All error handling details

static boolean|JException setErrorHandling( integer $level, string $mode, mixed $options = null)

Method to set the way the JError will handle different error levels. Use this if you want to override the default settings.

Error handling modes: - ignore - echo - verbose - die - message - log - callback

You may also set the error handling for several modes at once using PHP's bit operations. Examples: - EALL = Set the handling for all levels - EERROR | EWARNING = Set the handling for errors and warnings - EALL ^ E_ERROR = Set the handling for all levels except errors

Parameters

integer $level The error level for which to set the error handling
string $mode The mode to use for the error handling.
mixed $options Optional: Any options needed for the given mode.

Return Value

boolean|JException True on success or a JException object if failed.

static void attachHandler()

Method that attaches the error handler to JError

Return Value

void

See also

set_error_handler

static void detachHandler()

Method that detaches the error handler from JError

Return Value

void

See also

restore_error_handler

static boolean registerErrorLevel( integer $level, string $name, string $handler = 'ignore')

Method to register a new error level for handling errors

This allows you to add custom error levels to the built-in - ENOTICE - EWARNING - E_NOTICE

Parameters

integer $level Error level to register
string $name Human readable name for the error level
string $handler Error handler to set for the new error level [optional]

Return Value

boolean True on success; false if the level already has been registered

static string|boolean translateErrorLevel( integer $level)

Translate an error level integer to a human readable string e.g. E_ERROR will be translated to 'Error'

Parameters

integer $level Error level to translate

Return Value

string|boolean Human readable error level name or boolean false if it doesn't exist

static JException handleIgnore( JException $error, array $options)

Ignore error handler - Ignores the error

Parameters

JException $error &$error Exception object to handle
array $options Handler options

Return Value

JException The exception object

See also

JError::raise()

static JException handleEcho( JException $error, array $options)

Echo error handler - Echos the error message to output

Parameters

JException $error &$error Exception object to handle
array $options Handler options

Return Value

JException The exception object

See also

JError::raise()

static JException handleVerbose( JException $error, array $options)

Verbose error handler - Echos the error message to output as well as related info

Parameters

JException $error &$error Exception object to handle
array $options Handler options

Return Value

JException The exception object

See also

JError::raise()

static void handleDie( JException $error, array $options)

Die error handler - Echos the error message to output and then dies

Parameters

JException $error &$error Exception object to handle
array $options Handler options

Return Value

void Calls die()

See also

JError::raise()

static JException handleMessage( JException $error, array $options)

Message error handler Enqueues the error message into the system queue

Parameters

JException $error &$error Exception object to handle
array $options Handler options

Return Value

JException The exception object

See also

JError::raise()

static JException handleLog( JException $error, array $options)

Log error handler Logs the error message to a system log file

Parameters

JException $error &$error Exception object to handle
array $options Handler options

Return Value

JException The exception object

See also

JError::raise()

static JException handleCallback( JException $error, array $options)

Callback error handler - Send the error object to a callback method for error handling

Parameters

JException $error &$error Exception object to handle
array $options Handler options

Return Value

JException The exception object

See also

JError::raise()

static void customErrorPage( JException $error)

Display a custom error page and exit gracefully

Parameters

JException $error Exception object

Return Value

void

static void customErrorHandler( integer $level, string $msg)

Display a message to the user

Parameters

integer $level The error level - use any of PHP's own error levels for this: EERROR, EWARNING, ENOTICE, EUSERERROR, EUSERWARNING, EUSER_NOTICE.
string $msg Error message, shown to user if need be.

Return Value

void

static string renderBacktrace( Exception $error)

Render the backtrace

Parameters

Exception $error The error

Return Value

string Contents of the backtrace