ExceptionHandler
Table of Contents
Methods
- __construct() : mixed
- ExceptionHandler constructor.
- getTrackModules() : array<string|int, mixed>
- handleAssertion() : void
- Creates and exception object from its arguments.
- handleError() : true
- Creates and exception object from its arguments.
- handleException() : void
- Writes exception information into log, displays it to user and terminates with die().
- handleFatalError() : void
- Gets error information from error_get_last() function.
- initialize() : void
- Initializes error handling.
- setAssertionErrorType() : void
- Sets assertion types to be handled.
- setAssertionThrowsException() : void
- Whenever to throw an exception on assertion or not.
- setDebugMode() : void
- Sets debug mode.
- setExceptionErrorsTypes() : void
- Sets which errors will raise an exception.
- setHandledErrorsTypes() : void
- Sets error types to be handled.
- setHandlerLog() : void
- Sets logger object to use for log writing.
- setHandlerOutput() : void
- Sets an object used for error message display to user.
- setIgnoreSilence() : void
- Whenever to ignore error_reporting() == 0 or not.
- setOverflowMemoryCatching() : void
- Whenever to try catch and report memory overflows errors or not.
- setTrackModules() : void
- writeToLog() : void
- Writes an exception information to log.
Methods
__construct()
ExceptionHandler constructor.
public
__construct() : mixed
getTrackModules()
public
getTrackModules() : array<string|int, mixed>
Return values
array<string|int, mixed>handleAssertion()
Creates and exception object from its arguments.
public
handleAssertion(string $file, int $line, string $message) : void
Throws it if assertion set to raise exception (which is by default) or writes it to log.
Parameters
- $file : string
-
File where error has occurred.
- $line : int
-
File line number where error has occurred.
- $message : string
-
Error message.
Tags
handleError()
Creates and exception object from its arguments.
public
handleError(int $code, string $message, string $file, int $line) : true
Throws it if $code matches exception mask or writes it into log.
Parameters
- $code : int
-
Error code.
- $message : string
-
Error message.
- $file : string
-
File where error has occurred.
- $line : int
-
File line number where error has occurred.
Tags
Return values
truehandleException()
Writes exception information into log, displays it to user and terminates with die().
public
handleException(Exception|Error $exception[, int $logType = ExceptionHandlerLog::UNCAUGHT_EXCEPTION ]) : void
Parameters
- $exception : Exception|Error
-
Exception object.
- $logType : int = ExceptionHandlerLog::UNCAUGHT_EXCEPTION
Tags
handleFatalError()
Gets error information from error_get_last() function.
public
handleFatalError() : void
Checks if type for certain error types and writes it to log.
Tags
initialize()
Initializes error handling.
public
initialize(callable $exceptionHandlerOutputCreator[, callable|null $exceptionHandlerLogCreator = null ]) : void
Must be called after the object creation.
Parameters
- $exceptionHandlerOutputCreator : callable
-
Function to return an object for error message formatting.
- $exceptionHandlerLogCreator : callable|null = null
-
Function to return an object for log writing.
setAssertionErrorType()
Sets assertion types to be handled.
public
setAssertionErrorType(int $assertionErrorType) : void
Parameters
- $assertionErrorType : int
-
Bitmask of assertion types.
Tags
setAssertionThrowsException()
Whenever to throw an exception on assertion or not.
public
setAssertionThrowsException(bool $assertionThrowsException) : void
Parameters
- $assertionThrowsException : bool
-
If true an assertion will throw exception.
setDebugMode()
Sets debug mode.
public
setDebugMode(bool $debug) : void
Should be used for development install.
Parameters
- $debug : bool
-
If true errors will be displayed in html output. If false most errors will be suppressed.
setExceptionErrorsTypes()
Sets which errors will raise an exception.
public
setExceptionErrorsTypes(int $errorTypesException) : void
Parameters
- $errorTypesException : int
-
Bitmask of error types.
Tags
setHandledErrorsTypes()
Sets error types to be handled.
public
setHandledErrorsTypes(int $handledErrorsTypes) : void
Parameters
- $handledErrorsTypes : int
-
Bitmask of error types.
Tags
setHandlerLog()
Sets logger object to use for log writing.
public
setHandlerLog([ExceptionHandlerLog|null $handlerLog = null ]) : void
Parameters
- $handlerLog : ExceptionHandlerLog|null = null
-
Logger object.
setHandlerOutput()
Sets an object used for error message display to user.
public
setHandlerOutput(IExceptionHandlerOutput $handlerOutput) : void
Parameters
- $handlerOutput : IExceptionHandlerOutput
-
Object will display errors to user.
setIgnoreSilence()
Whenever to ignore error_reporting() == 0 or not.
public
setIgnoreSilence(bool $ignoreSilence) : void
Parameters
- $ignoreSilence : bool
-
If true then error_reporting()==0 will be ignored.
setOverflowMemoryCatching()
Whenever to try catch and report memory overflows errors or not.
public
setOverflowMemoryCatching(bool $catchOverflowMemory) : void
Parameters
- $catchOverflowMemory : bool
-
If true memory overflow errors will be handled.
setTrackModules()
public
setTrackModules(array<string|int, mixed> $trackModules) : void
Parameters
- $trackModules : array<string|int, mixed>
writeToLog()
Writes an exception information to log.
public
writeToLog(Throwable $exception[, int|null $logType = null ]) : void
Parameters
- $exception : Throwable
-
Exception object.
- $logType : int|null = null
-
See ExceptionHandlerLog class constants.