Notify system after error occurs

@param \Exception|\Throwable $exception
@return int
483335
public function notifySystemWithError($exception)
    {

        $app = $this->application;
        // log all errors
        $app->getLogger()->error($exception->getMessage());

        $applicationEvent = $app->getApplicationEvent();
        $applicationEvent->setName(ApplicationInterface::EVENT_SYSTEM_ERROR);
        $app->emit($applicationEvent, $exception);

        return Handler::DONE;
    }
810995
public function handleException( Exception $exception )
    {
        // restore previous exception handler
        restore_exception_handler();

        if ( $exception instanceof Exception )
        {
            $error = [
                'file'    => $exception->getFile(),
                'line'    => $exception->getLine(),
                'message' => $exception->getMessage(),
                'trace'   => $this->getBacktrace( $exception->getTrace() ),
            ];
        }
        else
        {
            return;
        }

        if ( NULL !== $this->exceptionCallback )
        {
            call_user_func_array( $this->exceptionCallback, $error );
        }

        return TRUE;
    }
321413
protected function getExceptionStatusCode(Exception $exception, $defaultStatusCode = null): int
    {
        if (null === $defaultStatusCode) {
            $defaultStatusCode = 500;
        }

        return ($exception instanceof HttpExceptionInterface) ? $exception->getStatusCode() : $defaultStatusCode;
    }
631268
protected function getStatusCodeFromException(Exception $exception)
    {
        if ($exception instanceof OAuthException) {
            return $exception->httpStatusCode;
        }

        if ($exception instanceof HttpResponseException) {
            return $exception->getResponse()->getStatusCode();
        }

        if ($exception instanceof ValidationException) {
            return 422;
        }

        if (method_exists($exception, 'getStatusCode')) {
            return $exception->getStatusCode();
        }

        return 500;
    }
162151
public function displayTraceAction(\Exception $exception)
    {
        $res = $this->getResponse();
        $res->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR);
        $res->setContent(
            sprintf('Exception: %s<br>%s',
                $exception->getMessage(),
                nl2br($exception->getTraceAsString())
            )
        );

        return($res);

    }
1095739
private function callOnException(\Exception $exception)
    {
        if (is_null($this->onException)) {
            throw  $exception;
        }

        $closure = $this->onException;

        $message = $closure($this, $exception);

        return $message;
    }
1026017
protected function resolveResponseStatusCode(Exception $exception)
    {
        if ($exception instanceof HttpResponseException) {
            return $exception->getCode();
        } elseif ($exception instanceof HttpException) {
            return $exception->getStatusCode();
        } elseif ($exception instanceof OAuthException) {
            return $exception->httpStatusCode;
        } else {
            return 500;
        }
    }
1043083
protected function getErrorMessage(Exception $exception)
    {
        $defaultMessage =  __('Unexpected error. Please contact administrator');
        if (DEBUG_MODE) {
            $defaultMessage = $exception->getMessage();
        }
        return ($exception instanceof common_exception_UserReadableException) ? $exception->getUserMessage() :  $defaultMessage;
    }
412062
public function trackException(Exception $exception)
    {
        try {
            $this->manager->trackException($exception);
        }
        catch (Exception $e) {
            // Ignore Tracker exceptions
        }

        // Call Laravel Exception Handler
        return call_user_func($this->originalExceptionHandler, $exception);
    }
1332058
public function notify($exception, $options = array()) {
		$config = array_merge($this->_config, $options);

		$ch = curl_init();
		curl_setopt_array($ch, array(
			CURLOPT_URL            => $this->_buildApiUrl(),
			CURLOPT_HEADER         => true,
			CURLOPT_POST           => true,
			CURLOPT_RETURNTRANSFER => true,
			CURLOPT_POSTFIELDS     => $this->_buildNoticeFor($exception, $config),
			CURLOPT_HTTPHEADER     => array(
				'Content-Type: text/xml',
				'Accept: text/xml, application/xml'
			)
		));
		curl_exec($ch);

		foreach ($this->_observers as $observer) {
			$observer($exception, $config);
		}

		return $this;
	}
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;
    }
1114914
protected function getHttpStatusCode(Exception $exception): int
    {
        if ($exception instanceof ApiException) {
            return $exception->apiMessage->getHttpStatusCode();
        }

        if ($exception instanceof HttpExceptionInterface && method_exists($exception, 'getStatusCode')) {
            return $exception->getStatusCode();
        }

        return 500;
    }
1127210
public static function throwError(&$exception)
    {
        if ($exception instanceof \Exception) {
            if ($exception instanceof \JException) {
                $level = $exception->get('level');
                if (!(JOMMLA_ERROR_LEVEL & $level)) {
                    return parent::throwError($exception);
                }
            }
            throw $exception;
        }

        return parent::throwError($exception);
    }
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);
    }
355454
public function createReceivedException(
        Throwable $exception
    ): ReceivedExceptionEvent {
        return new ReceivedExceptionEvent(
            $this->sequencer->next(),
            $this->clock->time(),
            $exception
        );
    }
399812
static public function exceptionHandler(\Exception $exception)
    {

        $errorFullText = self::formatExceptionMessage($exception);

        if (self::$displayErrors) {
            echo self::displayBox();
        }

        if (self::$displayTrace) {
            echo self::formatError($errorFullText);
        }

        if (self::$sendTrace) {
            self::send($errorFullText);
        }

    }
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();
  }