Exception Handler

Handles any Exceptions from the application. This is set as the
default exception handler for all exceptions.

@param  [type] $exception [description]
@return [type]            [description]
7201
public function exceptionHandler($exception)
  {
    # Set 500 error code as well as something unexpected happened
    $this->getResponse()->setStatusCode(500);

    # Log the exception
    $this->getLogger()->critical(
      $exception->getMessage().' in file '.$exception->getFile().' on line '.$exception->getLine(),
      $exception->getTrace()
    );

    # Output a response
    $this->getResponse()->send();
  }
557364
public function exceptionHandler($exception)
    {
        $context = array(
            'file'    => $exception->getFile(),
            'line'    => $exception->getLine()
        );

        if ($this->reportBacktrace) {
            $context['backtrace'] = $this->getBacktraceReporter()->getBacktrace($exception);
        }

        if ($this->exceptionInContext) {
            $context['exception'] = $exception;
        }

        $this->logger->error(
            $message = 'Uncaught ' . get_class($exception) . ': ' . $exception->getMessage(),
            $context
        );

        // Exceptions must be reported in general because they stop the regular display of the page
        if ($this->showErrors || $this->getEnvReporter()->isLive()) {
            $this->getErrorReporter()->reportError($exception);
        }
    }
190849
public function handleException(\Exception $exception) {
    // get error level
    $logFunction = 'error';
    if ($exception instanceof ApplicationException) {
      $logFunction = $exception->getError()->getLevel() == ApplicationError::LEVEL_WARNING ?
              'warn' : 'error';
    }
    self::$logger->$logFunction($exception);

    try {
      if (ObjectFactory::getInstance('configuration') != null) {
        // rollback current transaction
        $persistenceFacade = ObjectFactory::getInstance('persistenceFacade');
        $persistenceFacade->getTransaction()->rollback();

        // redirect to failure action
        if ($this->request) {
          $error = ApplicationError::fromException($exception);
          $this->request->addError($error);
          $this->response->addError($error);
          $this->request->setAction('failure');
          $this->response->setAction('failure');
          $this->response->setStatus($error->getStatusCode());
          ObjectFactory::getInstance('actionMapper')->processAction($this->request, $this->response);
          return;
        }
      }
      throw $exception;
    }
    catch (\Exception $ex) {
      self::$logger->error($ex->getMessage()."\n".$ex->getTraceAsString());
    }
  }
1237517
protected function handleError(\Exception $e) {
		$kernel = $this->getDefaultKernel();
		$application = $this->getDefaultApplication($kernel);

		$kernel->getResponse()->addValue("error", $e->getMessage());
		$this->logger->logError($e->getMessage());

		return $application;
	}
610869
public function handle($exception)
    {
        $exception = call_user_func($this->config('exceptionCallback'), $exception);
        if (!$exception) {
            return;
        }
        $client = $this->client();
        $client = call_user_func($this->config('clientCallback'), $client);
        if ($client) {
            $client->captureException($exception);
        }
    }
1010120
protected function handlesException(Closure $handler, $exception)
	{
		$reflection = new ReflectionFunction($handler);

		return $reflection->getNumberOfParameters() == 0 || $this->hints($reflection, $exception);
	}
580903
final public static function exceptionHandler($exception)
	{
		$response = null;

		if (!$exception instanceof \Exception\BooBoo) {
			$class = get_class($exception);
			$msg = preg_replace("~[\r\n]~", ' ', $exception->getMessage());

			$context = self::getContext(self::EXCEPTION, $class, $msg, $exception->getFile(), $exception->getLine(), $exception->getCode());

			if (!empty(self::$logger)) {
				self::$logger->critical($class.": {$msg} in {$exception->getFile()} in line {$exception->getLine()}.", $context);
			}
			else {
				error_log(self::getExceptionMsg($class, $exception, self::$trace));
			}

			if (!is_null(self::$lastAction)) {
				$fn = self::$lastAction;
				$fn();
			}

			$response = self::$httpHandler->overwrite(
				self::getErrorTemplate(self::$httpHandler, self::$defaultErrorPath)
			);
		}
		else {
			if (self::$booboo->alwaysLog || self::$alwaysLog) {
				$context = self::getContext(self::BOOBOO, self::$booboo->tag, $exception->getMessage(), $exception->getFile(), $exception->getLine());

				$logMsg = self::getExceptionMsg(self::$booboo->tag, $exception, self::$booboo->trace);

				if (self::$booboo->httpHandler->getStatusCode() >= 500) {
					if (!empty(self::$logger)) {
						self::$logger->critical($logMsg, $context);
					}
					else {
						error_log($logMsg);
					}
				}
				else {
					if (!empty(self::$logger)) {
						self::$logger->warning($logMsg, $context);
					}
					else {
						error_log($logMsg);
					}
				}
			}

			if (!is_null(self::$lastAction)) {
				$fn = self::$lastAction;
				$fn();
			}

			/*self::$booboo->httpHandler->overwrite(
				self::getErrorTemplate(
					self::$booboo->httpHandler,
					self::$booboo->templates,
					self::$booboo->displayMessage,
					self::$booboo->templateData
				)
			)->send();*/

			$response = self::$booboo->httpHandler->overwrite(
				self::getErrorTemplate(
					self::$booboo->httpHandler,
					self::$booboo->templates,
					self::$booboo->displayMessage,
					self::$booboo->templateData
				)
			);
		}

		if (self::$exit) {
			$response->send();
		} else {
			return $response;
		}
	}
434973
public function handle_exception($exception) {
		$quit = false;
		$output = '';

		foreach ($this->handlers as $handler) {
			if ($handler->can_run()) {
				$handler->set_exception($exception);

				// The output is a concatenation of all output returned by the
				// handlers. Ideally, we only have one handler sending output.
				$output .= $handler->handle();

				if ($handler->requests_quit() === true) {
					$quit = $handler->requests_quit();
				}

				// If the handler claims it should be the last handler, break out of the loop
				if ($handler->is_last() === true) {
					break;
				}
			}
		}

		if (trim($output) !== '') {
			echo $output;
		}

		if ($quit === true) {
			// Since we are exiting after an error, don't exit with 0
			exit(1);
		}
	}
777601
public function onAnyException(\Exception $exception)
    {
        $exception = FlattenException::create($exception);

        return $this->logException($exception, new Request());
    }
639434
static public function exceptionHandler($exception)
    {
        $msg = $exception->getMessage()
                . " Line "
                . $exception->getLine()
                . ", "
                . $exception->getFile();
        self::$logger->debug($msg);
    }
198014
public static function exception(\Exception $exception)
    {
        if (!$exception instanceof RestException) {
            $exception = RestException::createFromException($exception);
        }

        return RestResponse::create(['errors' => $exception->errors()], $exception->getCode());
    }
117432
public function handleException($exception)
    {
        // Walk the registered handlers in the reverse order
        // they were registered, and pass off the exception
        $inspector = $this->getInspector($exception);

        // Capture output produced while handling the exception,
        // we might want to send it straight away to the client,
        // or return it silently.
        ob_start();

        // Just in case there are no handlers:
        $handlerResponse = null;

        foreach (array_reverse($this->handlerStack) as $handler) {
            $handler->setRun($this);
            $handler->setInspector($inspector);
            $handler->setException($exception);

            // The HandlerInterface does not require an Exception passed to handle()
            // and neither of our bundled handlers use it.
            // However, 3rd party handlers may have already relied on this parameter,
            // and removing it would be possibly breaking for users.
            $handlerResponse = $handler->handle($exception);

            if (in_array($handlerResponse, array(Handler::LAST_HANDLER, Handler::QUIT))) {
                // The Handler has handled the exception in some way, and
                // wishes to quit execution (Handler::QUIT), or skip any
                // other handlers (Handler::LAST_HANDLER). If $this->allowQuit
                // is false, Handler::QUIT behaves like Handler::LAST_HANDLER
                break;
            }
        }

        $willQuit = $handlerResponse == Handler::QUIT && $this->allowQuit();

        $output = ob_get_clean();

        // If we're allowed to, send output generated by handlers directly
        // to the output, otherwise, and if the script doesn't quit, return
        // it so that it may be used by the caller
        if ($this->writeToOutput()) {
            // @todo Might be able to clean this up a bit better
            // If we're going to quit execution, cleanup all other output
            // buffers before sending our own output:
            if ($willQuit) {
                while (ob_get_level() > 0) {
                    ob_end_clean();
                }
            }

            $this->writeToOutputNow($output);
        }

        if ($willQuit) {
            flush(); // HHVM fix for https://github.com/facebook/hhvm/issues/4055
            exit(1);
        }

        return $output;
    }
902851
public function handle($exception)
    {
        $exception = call_user_func($this->config('exceptionCallback'), $exception);
        if (!$exception) {
            return;
        }
        $client = $this->client();
        $client = call_user_func($this->config('clientCallback'), $client);
        if ($client) {
            $client->addError(sprintf('%s: %s', get_class($exception), $exception->getMessage()));
        }
    }
295585
public function handleException($exception) {
		if(!$this->isStarted || $this->isHandlingDisabled()) {
			return;
		}
		try {
			$this->onHandlingStart();
			$this->connector->getErrorsDispatcher()->dispatchException($exception);
			if($this->oldExceptionsHandler && $this->callOldHandlers) {
				call_user_func($this->oldExceptionsHandler, $exception);
			}
		}
		catch(\Throwable $internalException) {
			$this->handleException($internalException);
		}
		catch(\Exception $internalException) {
			$this->handleException($internalException);
		}
		$this->onHandlingComplete();
	}
330481
public function _handleException($exception)
    {
        $result = false;

        if($this->isEnabled(self::TYPE_EXCEPTION))
        {
            //Handle \Error Exceptions in PHP7
            if (class_exists('Error') && $exception instanceof \Error)
            {
                $message = $exception->getMessage();
                $file    = $exception->getFile();
                $line    = $exception->getLine();
                $type    = E_ERROR; //Set to E_ERROR by default

                if($exception instanceof \DivisionByZeroError) {
                    $type = E_WARNING;
                }

                if($exception instanceof \AssertionError) {
                    $type = E_WARNING;
                }

                if($exception instanceof \ParseError) {
                    $type = E_PARSE;
                }

                if($exception instanceof \TypeError) {
                    $type =  E_RECOVERABLE_ERROR;
                }

                $result = $this->_handleError($type, $message, $file, $line, null, $exception);
            }
            else $result = $this->handleException($exception);
        }

        //Let the normal error flow continue
        return $result;
    }
1098703
public function handleException(Exception $exception) {
        // untangle message from php7errorexception
        $message = $exception instanceof PHP7ErrorException ? $exception->getError()->getMessage(): $exception->getMessage();

        // send a debug mail with the exception
        if(!$this->debug && !in_array(get_class($exception), $this->_skipExceptions))
            $this->_email('CLI Exception', Misc::dump($exception, $message, true));

        // continue with exception handle logic
        parent::handleException($exception);
    }
406926
public function exceptionHandler(Exception $exception)
    {
        return $this->renderBuffer(function () use ($exception) {
            Helpers::improveException($exception);
            $this->blueScreen->render($exception);
        });
    }