Converts an exception type thrown by Halcyon to a native CMS exception.
@param Exception $ex
429760
protected function throwHalcyonSaveException(Exception $ex)
    {
        if ($ex instanceof \October\Rain\Halcyon\Exception\MissingFileNameException) {
            throw new ValidationException([
                'fileName' => Lang::get('cms::lang.cms_object.file_name_required')
            ]);
        }
        elseif ($ex instanceof \October\Rain\Halcyon\Exception\InvalidExtensionException) {
            throw new ValidationException(['fileName' =>
                Lang::get('cms::lang.cms_object.invalid_file_extension', [
                    'allowed' => implode(', ', $ex->getAllowedExtensions()),
                    'invalid' => $ex->getInvalidExtension()
                ])
            ]);
        }
        elseif ($ex instanceof \October\Rain\Halcyon\Exception\InvalidFileNameException) {
            throw new ValidationException([
               'fileName' => Lang::get('cms::lang.cms_object.invalid_file', ['name'=>$ex->getInvalidFileName()])
            ]);
        }
        elseif ($ex instanceof \October\Rain\Halcyon\Exception\FileExistsException) {
            throw new ApplicationException(
                Lang::get('cms::lang.cms_object.file_already_exists', ['name' => $ex->getInvalidPath()])
            );
        }
        elseif ($ex instanceof \October\Rain\Halcyon\Exception\CreateDirectoryException) {
            throw new ApplicationException(
                Lang::get('cms::lang.cms_object.error_creating_directory', ['name' => $ex->getInvalidPath()])
            );
        }
        elseif ($ex instanceof \October\Rain\Halcyon\Exception\CreateFileException) {
            throw new ApplicationException(
                Lang::get('cms::lang.cms_object.error_saving', ['name' => $ex->getInvalidPath()])
            );
        }
        else {
            throw $ex;
        }
    }
1222299
public function expandException($ex, &$result = array(), $limit = 10)
    {
        $result[] = $ex;
        if ($ex->getPrevious()) {
            if ($limit > 0) {
                $this->expandException($ex->getPrevious(), $result, $limit - 1);
            }
        }
        return $result;
    }
1305983
public function formatException(\Exception $ex)
    {
        return sprintf(
            $this->errorMessageFormat,
            $ex->getMessage(),
            $ex->getCode(),
            $ex->getFile(),
            $ex->getLine(),
            get_class($ex)
        );
    }
310726
public static function printException(\Exception $ex)
    {
        $msg="code:".$ex->getCode()
            ."\r\nmessage:".$ex->getMessage()
            ."\r\ntrace:".$ex->getTraceAsString();
        self::printLine($msg);
    }
286185
private function convertToGoogleException($ex)
    {
        switch ($ex->getCode()) {
            case Code::INVALID_ARGUMENT:
                $exception = Exception\BadRequestException::class;
                break;

            case Code::NOT_FOUND:
            case Code::UNIMPLEMENTED:
                $exception = Exception\NotFoundException::class;
                break;

            case Code::ALREADY_EXISTS:
                $exception = Exception\ConflictException::class;
                break;

            case Code::FAILED_PRECONDITION:
                $exception = Exception\FailedPreconditionException::class;
                break;

            case Code::UNKNOWN:
                $exception = Exception\ServerException::class;
                break;

            case Code::INTERNAL:
                $exception = Exception\ServerException::class;
                break;

            case Code::ABORTED:
                $exception = Exception\AbortedException::class;
                break;

            case Code::DEADLINE_EXCEEDED:
                $exception = Exception\DeadlineExceededException::class;
                break;

            default:
                $exception = Exception\ServiceException::class;
                break;
        }

        $metadata = [];
        if ($ex->getMetadata()) {
            foreach ($ex->getMetadata() as $type => $binaryValue) {
                if (!isset($this->metadataTypes[$type])) {
                    continue;
                }
                $metadataElement = new $this->metadataTypes[$type];
                $metadataElement->mergeFromString($binaryValue[0]);
                $metadata[] = $this->serializer->encodeMessage($metadataElement);
            }
        }

        return new $exception($ex->getMessage(), $ex->getCode(), $ex, $metadata);
    }
262881
protected function getJsonReponseFromException(Exception $ex)
    {
        $authorizationChecker = $this->get('security.authorization_checker');
        $logger = $this->get('logger');

        //can we see the debug
        $isDebugAllowed = $authorizationChecker->isGranted('ROLE_VICTOIRE_PAGE_DEBUG') ? true : $this->get('kernel')->isDebug();

        //whatever is the exception, we log it
        $logger->error($ex->getMessage());
        $logger->error($ex->getTraceAsString());

        if ($isDebugAllowed) {
            throw $ex;
        } else {
            //translate the message
            $translator = $this->get('translator');

            //get the translated message
            $message = $translator->trans('error_occured', [], 'victoire');

            $response = new JsonResponse(
                [
                    'success' => false,
                    'message' => $message,
                ]
            );
        }

        return $response;
    }
916470
public function exitWithException($ex)
    {
        $response_data = [];
    
        $response_data["result"] = "error";
    
        $response_data["errors"] = [
            ["error_code" => "system_error", "error_text" => $ex->getMessage()]
        ];
    
        $this->sendJsonResponse($response_data);
        
        exit;
    }
484253
private function convertToMountebankException(ClientException $e)
    {
        return $this->exceptionFactory->createInstanceFromMountebankResponse(
            (string)$e->getResponse()->getBody()
        );
    }
814512
protected function handleError(Exception $e)
    {
        if($this->isCli){
            $errorCode = $e->getCode();
            exit((empty($errorCode)) ? 1 : $errorCode);	//exit the program with an error
        }
        else {
            throw new Exception($e->getMessage());
        }
    }
1004492
private function handleException($ex) {
    self::$logger->error($ex->getMessage()."\n".$ex->getTraceAsString());
    $this->fault('SOAP-ENV:SERVER', $ex->getMessage(), '', '');
  }
215871
protected function convertExceptionToResponse(Exception $e)
    {
        return SymfonyResponse::create(
            $this->renderExceptionContent($e),
            $this->isHttpException($e) ? $e->getStatusCode() : 500,
            $this->isHttpException($e) ? $e->getHeaders() : []
        );
    }
694831
public function logException(\Exception $ex,$prefix="ex")
    {
        $this->log($ex->getCode().":".$ex->getMessage()."\r\n".$ex->getTraceAsString(),get_class($ex),$prefix);
    }
1220783
private static void _invokeCustomExceptionCallback (@Nonnull final Throwable ex)
  {
    s_aExceptionCallbacks.forEach (x -> x.onException (ex));
  }
408023
public function exception_handler($ex) {
        // detect active db transactions, rollback and log as error
        abort_all_db_transactions();

        // some hacks might need a cleanup hook
        $this->session_cleanup($ex);

        // now let the plugin send the exception to client
        $this->send_error($ex);

        // not much else we can do now, add some logging later
        exit(1);
    }
624623
private EJBException mapException(Throwable ex)
    {
        EJBException ejbex;
        boolean createdEx = true;
        Exception causeEx = null;

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.entry(tc, "mapException: " + ex);

        // -----------------------------------------------------------------------
        // First, obtain the message text used to create the exception.
        //
        // If the message being mapped ends up being 'replaced', then the
        // replacement should have the same message text.
        //
        // getBaseMessage insures that the message text does NOT include the
        // name of the exception class, nor any chained exception text.
        // -----------------------------------------------------------------------
        String message = ExceptionUtil.getBaseMessage(ex);

        // -----------------------------------------------------------------------
        // Second, get the cause of the exception being mapped.
        //
        // findCause will remove any internal EJB Container exceptions from
        // the exception chain.
        //
        // Also, if the cause is not a subclass of Throwable, then it must
        // be 'wrapped' in an Exception, as EJBException does not allow
        // Throwable on any of its constructors.  However, the 'cause' on
        // throwable will still be set to the intended cause.  This will allow
        // getCause() to work as expected, even though EJBException does not
        // support Throwable.
        // -----------------------------------------------------------------------
        Throwable cause = ExceptionUtil.findCause(ex);

        if (cause != null)
        {
            if (cause instanceof Exception)
            {
                causeEx = (Exception) cause;
            }
            else
            {
                causeEx = new Exception("See nested Throwable", cause);
            }
        }

        // -----------------------------------------------------------------------
        // Next, map Throwable to an EJBException to return.
        //
        // These mappings are prescribed by the EJB & ActivitySession specs.
        //
        // Note: When adding new mappings, do NOT call 'initCause', as that
        //       will be performed below, and handles the fact that EJBException
        //       may not be created with a throwable.
        //
        // Caution: Do NOT look at the cause to perform mapping. If an exception
        //          is 'wrapped' in another exception, it likely was wrapped
        //          by another EJB method call, and a failure from a downstream
        //          method call should NOT be treated the same here.
        //          If it appears the cause needs to be examined, then instead,
        //          find the code that wrapped the cause, and stop wrapping it.
        // -----------------------------------------------------------------------
        if (ex instanceof CSIException)
        {
            ejbex = mapCSIException((CSIException) ex, causeEx, cause);
            createdEx = false;
        }
        else if (ex instanceof NoSuchObjectException)
        {
            ejbex = new NoSuchEJBException(message, causeEx);
        }
        else if (ex instanceof EJBStoppedException) // d350987
        {
            // Don't just replace the EJBStoppedException, but nest it as the
            // cause so applications may check for it.
            cause = ex;
            causeEx = (Exception) ex;
            ejbex = new NoSuchEJBException((String) null, causeEx);
        }
        else if (ex instanceof TransactionRequiredException)
        {
            ejbex = new EJBTransactionRequiredException(message); // d395666
        }
        else if (ex instanceof TransactionRolledbackException)
        {
            ejbex = new EJBTransactionRolledbackException(message, causeEx); // d395666
        }
        else if (ex instanceof InvalidTransactionException)
        {
            ejbex = new InvalidTransactionLocalException(message, causeEx);
        }
        else if (ex instanceof AccessException)
        {
            ejbex = new EJBAccessException(message); // d395666
        }
        //        else if (ex instanceof ActivityRequiredException)
//        {
//            ejbex = new ActivityRequiredLocalException(message, causeEx);
//        }
//        else if (ex instanceof InvalidActivityException)
//        {
//            ejbex = new InvalidActivityLocalException(message, causeEx);
//        }
//        else if (ex instanceof ActivityCompletedException)
//        {
//            ejbex = new ActivityCompletedLocalException(message, causeEx);
//        }
        else if (ex instanceof BeanNotReentrantException)
        {
            BeanNotReentrantException bnre = (BeanNotReentrantException) ex;
            if (bnre.isTimeout())
            {
                // EJB 3.1 has defined an exception for this purpose.      d653777.1
                ejbex = new ConcurrentAccessTimeoutException(message);
            }
            else
            {
                // EJB 3.0 has defined an exception for this purpose.      d366807.6
                ejbex = new ConcurrentAccessException(message, causeEx);
            }
        }
        else
        {
            // --------------------------------------------------------------------
            // All other exceptions are just be mapped to an EJBException.
            //
            // If the exception is an EJBException, it will just be returned
            // (with the throwable cause filled in), else the exception will
            // just be wrapped in an EJBException, with the stack and cause
            // set appropriately.
            // --------------------------------------------------------------------
            ejbex = ExceptionUtil.EJBException(ex);
            createdEx = false;
        }

        // -----------------------------------------------------------------------
        // Finally, EJBException doesn't normally set the cause on Throwable,
        // so let's do that to be nice :-) and clear the stack of the
        // EJBException, as it is mostly confusing and causes very
        // similar stacks to be printed out twice.
        //
        // Note that this code, especially clearing of the stack, is only
        // performed for EJBExceptions that were created in this method.
        // EJBExceptions that will just be propagated should NOT have the
        // stack cleared, as they were likely thrown by the customer.
        // -----------------------------------------------------------------------
        if (createdEx)
        {
            if (causeEx != null)
            {
                // Intentionally, the 'cause' is set as the 'cause', and not
                // 'causeEx'.  They will be the same, except when 'causeEx'
                // is just a silly wrapper around a Throwable.
                //
                // Geronimo EJBException.getCause returns getCausedbyException, so
                // we do not expect this code to be used.                     F53643
                if (ejbex.getCause() == null) { //F743-16279
                    // Use the 'real' cause here, not the possibly wrapped one.
                    ejbex.initCause(cause);
                }
            }
            else
            {
                ejbex.setStackTrace(ex.getStackTrace());
            }
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.exit(tc, "mapException returning: " + ejbex);

        return ejbex;
    }
1034559
public function handleException ($ex) {

        $inDebugMode = get_property("app.debug") || get_request("debug");

        if (!$inDebugMode) {
            if (get_property("app.log_errors")) {
                get_logger()->error($ex);
            }

            if (get_property("app.email_errors")) {

                $recipients = get_property("app.email_error_recipients");
                if (!empty($recipients)) {
                    $emailContent = '';
                    $emailContent .= '<b><u>Error report</u></b>';
                    $emailContent .= "<br><br>";
                    $emailContent .= get_class($ex);
                    $emailContent .= ": ";
                    $emailContent .= $ex->getMessage();
                    $emailContent .= " in file ";
                    $emailContent .= $ex->getFile();
                    $emailContent .= " on line ";
                    $emailContent .= $ex->getLine();
                    $emailContent .= "<br><br>";
                    $emailContent .= "<b>Stack trace: </b>";
                    $emailContent .= "<br>";
                    $frames = $ex->getTrace();
                    $lineNumber = 1;
                    foreach ($frames as $frame) {
                        $emailContent .= "<br>";
                        $emailContent .= ($lineNumber++);
                        $emailContent .= ". ";
                        if (!empty($frame["class"])) {
                            $emailContent .= $frame["class"];
                        }
                        if (!empty($frame["type"])) {
                            $emailContent .= $frame["type"];
                        }
                        if (!empty($frame["function"])) {
                            $emailContent .= $frame["function"];
                        }
                        $emailContent .= "() ";
                        $emailContent .= "<u><span style=\"color:#4288CE;\">";
                        if (!empty($frame["file"])) {
                            $emailContent .= $frame["file"];
                        }
                        if (!empty($frame["line"])) {
                            $emailContent .= ":";
                            $emailContent .= $frame["line"];
                        }
                        $emailContent .= "</span></u>";
                    }

                    $emailContent .= "<br>";

                    if (!empty($_SESSION)) {
                        $emailContent .= "<br>";
                        $emailContent .= "<b>Session: </b>";
                        $emailContent .= "<pre>";
                        $emailContent .= print_r($_SESSION, true);
                        $emailContent .= "</pre>";
                    }

                    if (!empty($_REQUEST)) {
                        $emailContent .= "<br>";
                        $emailContent .= "<b>Request: </b>";
                        $emailContent .= "<pre>";
                        $emailContent .= print_r($_REQUEST, true);
                        $emailContent .= "</pre>";
                    }

                    if (!empty($_COOKIE)) {
                        $emailContent .= "<br>";
                        $emailContent .= "<b>Cookies: </b>";
                        $emailContent .= "<pre>";
                        $emailContent .= print_r($_COOKIE, true);
                        $emailContent .= "</pre>";
                    }

                    if (!empty($_SERVER)) {
                        $emailContent .= "<br>";
                        $emailContent .= "<b>Server: </b>";
                        $emailContent .= "<pre>";
                        $emailContent .= print_r($_SERVER, true);
                        $emailContent .= "</pre>";
                    }

                    $mailer = Mailer::create();
                    foreach ($recipients as $recipient) {
                        $mailer->addAddress($recipient);
                    }
                    $mailer->Subject = "Error Report";
                    $mailer->Body = $emailContent;
                    $mailer->send();
                }
            }
        }

        if (php_sapi_name() == "cli") {
            $whoops = new \Whoops\Run;
            $whoops->pushHandler(new \Whoops\Handler\PlainTextHandler());
            $whoops->handleException($ex);
        }
        else {
            if (get_request("returnException")) {
                Exceptions::flatten($ex);
                $response = get_response();
                $response->statusCode(Response::HTTP_INTERNAL_SERVER_ERROR);
                $response->contentType('text/plain');
                $response->content(serialize($ex));
                $response->send();
            }
            else {
                if ($inDebugMode) {
                    $request = get_request();
                    $whoops = new \Whoops\Run;
                    if ($request->ajax()) {
                        $whoops->pushHandler(new \Whoops\Handler\PlainTextHandler());
                    }
                    else {
                        $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler);
                    }
                    $whoops->handleException($ex);
                }
                else {
                    handle_error_code(Response::HTTP_INTERNAL_SERVER_ERROR);
                }
            }
        }
    }
406899
public function onException(\Throwable $ex)
    {
        // 日志处理
        Log::error($ex->getMessage(), [
            'trace'     => $ex->getTrace(),
            'errorFile' => $ex->getFile(),
            'errorLine' => $ex->getLine(),
        ]);
        // 请求上下文处理
        if(RequestContext::exsits())
        {
            RequestContext::destroy();
        }
    }