HarmoniErrorHandler
From Harmoni
Contents |
About
Runtime problems within Harmoni will always throw Exceptions rather than calling the die() or exit() methods directly. Errors and notices will still occur when coding mistakes are made, and the HarmoniErrorHandler helps to unify the printing and logging of both Errors and uncaught Exceptions.
The HarmoniErrorHandler
The HarmoniErrorHandler is singleton class (not a Service) that provides static callback methods that can be used for pretty-printing and logging of Errors and uncaught Exceptions. The HarmoniErrorHandler prints and logs Error message based on the settings of the error_reporting and display_errors directives. Whether or not errors are displayed, they will be logged if the fall within the current error_reporting level. Uncaught Exceptions will always be logged.
If it is desired to also log errors and exceptions to the default system log in addition to the Logging OSID, enable the log_errors directive.
When logging errors, the handler will first check for the availability of the Logging service and log the error or uncaught exception if possible. It will then print out a pretty HTML display of the error or exception. if display_errors is on.
Configuration example
/*********************************************************
* Set the HarmoniErrorHandler as the default exception Handler.
*********************************************************/
set_exception_handler(array('HarmoniErrorHandler', 'handleException'));
/*********************************************************
* Un-comment the following line to use the Harmoni error
* handling and logging method. This has the advantage that
* Logging entries are stored whenever errors are encountered.
*
* A disadvantage (if software is not developed in E_STRICT mode)
* is that every E_STRICT runtime notice will trigger a call
* to the error handling function even if they are subsequently
* ignored, resulting in performance degredation.
*
* Concerto 2.5.0 has been developed in E_STRICT reporting mode,
* so no notices or runtime notices should occur during normal
* operation.
*********************************************************/
set_error_handler(array('HarmoniErrorHandler', 'handleError'));
/*********************************************************
* PHP error reporting setting. uncomment to enable override
* of default environment.
*
* If the HarmoniErrorHandler is used (above), it will respect
* the error_reporting level and will ignore any errors that
* are not within the reporting level.
*********************************************************/
error_reporting(E_ALL | E_STRICT);
/*********************************************************
* If you wish to display errors and uncaught exceptions on
* the screen, uncomment the following line. This should
* not be used in production environments, but is VERY useful
* in development.
*
* If display_errors if Off, then any errors matching the current
* error_reporting level and all uncaught Exceptions will
* be logged, but not displayed on the screen.
*********************************************************/
ini_set('display_errors', 'On');
/*********************************************************
* If log_errors is turned on, then reported errors and
* Exceptions will be logged to the default system log
* as well as the Logging OSID (if used).
*********************************************************/
// ini_set('log_errors', '1');
/*********************************************************
* Un-comment the following lines to change the level of errors
* at which execution is halted. By default, the level is
* E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR
* meaning that notices and warnings will not halt execution.
*
* The syntax for this method is the same as for the
* error_reporting() function.
*
* This should not be used in production environments, but
* may be useful in development.
*********************************************************/
// $handler = HarmoniErrorHandler::instance();
// $handler->fatalErrors(E_ALL | E_STRICT);
Exception Classes
-
HarmoniException- This class is provided to categorize exceptions. All exceptions thrown from within the Harmoni implementation should extend HarmoniException or the OSID_Exception. -
Error- This class that extends theHarmoniExceptionis provided for backwards compatibility with existing Harmoni code.

