lithium\core\ErrorHandler::handle PHP Method

handle() public static method

Receives the handled errors and exceptions that have been caught, and processes them in a normalized manner.
public static handle ( object | array $info, array $scope = [] ) : boolean
$info object | array
$scope array
return boolean True if successfully handled, false otherwise.
    public static function handle($info, $scope = array())
    {
        $checks = static::$_checks;
        $rules = $scope ?: static::$_config;
        $handler = static::$_exceptionHandler;
        $info = is_object($info) ? $handler($info, true) : $info;
        $defaults = array('type' => null, 'code' => 0, 'message' => null, 'file' => null, 'line' => 0, 'trace' => array(), 'context' => null, 'exception' => null);
        $info = (array) $info + $defaults;
        $info['stack'] = static::trace($info['trace']);
        $info['origin'] = static::_origin($info['trace']);
        foreach ($rules as $config) {
            foreach (array_keys($config) as $key) {
                if ($key === 'conditions' || $key === 'scope' || $key === 'handler') {
                    continue;
                }
                if (!isset($info[$key]) || !isset($checks[$key])) {
                    continue 2;
                }
                if (($check = $checks[$key]) && !$check($config, $info)) {
                    continue 2;
                }
            }
            if (!isset($config['handler'])) {
                return false;
            }
            if (isset($config['conditions']) && ($call = $config['conditions']) && !$call($info)) {
                return false;
            }
            if (isset($config['scope']) && static::handle($info, $config['scope']) !== false) {
                return true;
            }
            $handler = $config['handler'];
            return $handler($info) !== false;
        }
        return false;
    }

Usage Example

 public function testExceptionSubclassCatching()
 {
     $self = $this;
     ErrorHandler::config(array(array('type' => 'Exception', 'handler' => function ($info) use($self) {
         $self->errors[] = $info;
     })));
     ErrorHandler::handle(new UnexpectedValueException('Test subclass'));
     $this->assertEqual(1, count($this->errors));
     $result = end($this->errors);
     $expected = 'Test subclass';
     $this->assertEqual($expected, $result['message']);
 }