Default exception handler

@param $__exc_objException
435656
public static function handleException(\Exception $__exc_objException)
    {
        if (class_exists('\QApplicationBase')) {
            \QApplicationBase::$ErrorFlag = true;
        }

        global $__exc_strType;
        if (isset($__exc_strType)) {
            return;
        } // error was already called, avoid endless looping

        $__exc_strType = "Exception";
        $__exc_errno = $__exc_objException->getCode();
        $__exc_strMessage = $__exc_objException->getMessage();
        //$__exc_strObjectType = $__exc_objReflection->getName();

        if ($__exc_objException instanceof \QCubed\Database\AbstractBase) {
            $__exc_objErrorAttribute = new ErrorAttribute("Database Error Number", $__exc_errno, false);
            $__exc_objErrorAttributeArray[0] = $__exc_objErrorAttribute;

            if ($__exc_objException->Query) {
                $__exc_objErrorAttribute = new ErrorAttribute("Query", $__exc_objException->Query, true);
                $__exc_objErrorAttributeArray[1] = $__exc_objErrorAttribute;
            }
        }

        if ($__exc_objException instanceof \QDataBindException) {
            if ($__exc_objException->Query) {
                $__exc_objErrorAttribute = new ErrorAttribute("Query", $__exc_objException->Query, true);
                $__exc_objErrorAttributeArray[1] = $__exc_objErrorAttribute;
            }
        }

        $__exc_strFilename = $__exc_objException->getFile();
        $__exc_intLineNumber = $__exc_objException->getLine();
        $__exc_strStackTrace = trim($__exc_objException->getTraceAsString());

        if (ob_get_length()) {
            //$__exc_strRenderedPage = ob_get_contents();
            ob_clean();
        }

        // Call to display the Error Page (as defined in configuration.inc.php)
        if (defined('QCUBED_ERROR_PAGE_PHP')) {
            require(__DOCROOT__ . QCUBED_ERROR_PAGE_PHP);
        } else {
            // Error in installer or similar - QCUBED_ERROR_PAGE_PHP constant is not defined yet.
            echo "error: errno: " . $__exc_errno . "<br/>" . $__exc_strMessage . "<br/>" . $__exc_strFilename . ":" . $__exc_intLineNumber . "<br/>" . $__exc_strStackTrace;
        }
        if (!defined('HHVM_VERSION')) {
            exit(); // HHVM bug. Will not display output if this gets executed here.
        }
    }
174034
public static function setupExceptionHandling() {
        $previous = set_exception_handler(self::$exceptionHandler=__CLASS__.'::handleException');

        /**
         * Detect entering of the script's shutdown phase to be capable of handling destructor exceptions during shutdown
         * differently and avoid otherwise fatal errors. Should be the very first function on the shutdown function stack.
         *
         * @see  http://php.net/manual/en/language.oop5.decon.php
         * @see  ErrorHandler::handleDestructorException()
         */
        register_shutdown_function(function() {
            self::$inShutdown = true;
        });
        return $previous;
    }
1151999
protected function reportException(Exception $e)
    {
        $handler = $this->app->make(ExceptionHandler::class);

        $handler->report($e);
    }
1004492
private function handleException($ex) {
    self::$logger->error($ex->getMessage()."\n".$ex->getTraceAsString());
    $this->fault('SOAP-ENV:SERVER', $ex->getMessage(), '', '');
  }
1056920
private function handleForConsole(Exception $e)
    {
        if ($e instanceof StopException) {
            $output = $e->getMessage();
        }
        else {
            $data = $this->convertException($e);
            $class = get_class($e);
            $file  = $this->stripFile($data['file']);
            $line  = $data['line'];
            $code  = $data['code'];

            // set the error message
            if ($e instanceof HttpException) {
                $message = http_status_text($data['status']) . ' (' . $data['status'] . ')';
                if (!empty($data['message'])) {
                    $message .=  '. ' . $data['message'];
                }
            }
            else if ($e instanceof QueryException) {
                $message = $data['message'] . '; sql: ' . $data['sql'];
            }
            else {
                $message = $data['message'];
            }

            $output = $class . ' in "' . $file . '", line ' . $line . ':' . PHP_EOL . $message . ' (code ' . $code . ')';
        }

        stdio()->error($output);

        $exitCode = $e->getCode();
        if ($exitCode === null) {
            $exitCode = Command::EXIT_FAILURE;
        }

        exit ($exitCode);
    }
652162
private static function handleRequestException (Throwable $ex) {
        ob_clean();
        $response = get_response();
        $response->clear();
        $errorRoutes = self::$errorRoutes->getRoutes();
        if (!empty($errorRoutes)) {
            foreach ($errorRoutes as $errorRoute) {
                $routeResult = self::executeAction($errorRoute->getAction(), array_merge($_REQUEST, $errorRoute->getParameters(), [Throwable::class => $ex, Exception::class => $ex]));
                if (!empty($routeResult)) {
                    $response->content($routeResult);
                }
            }
            $response->send();
        }
        else {
            throw $ex;
        }
    }
1167634
public static function exceptionHandler(\Exception $e)
    {
//echo __METHOD__;
        $error = Error::createFromException($e, Response::STATUS_ERROR);
        $status = method_exists($e, 'getStatus') ? $e->getStatus() : Response::STATUS_ERROR;
        Container::get('response')
            ->setStatus($status);
        Container::get('controller')
            ->addError($error)
            ->serve();
    }
267240
public function exceptionHandler($e) {
        if (method_exists($e, 'getType')) {
            $this->addError($e->getMessage(), $e->getFile(), $e->getLine(), $e->getType());
        }
        else {
            $this->addError($e->getMessage(), $e->getFile(), $e->getLine(), gettype($e));
        }
    }
983710
public function handleException($exception)
    {
        $isHandled = false;
        try {
            $isHandled = $this->handler->handle($exception);
        } catch (Exception $ex) {
        } catch (Throwable $ex) {
        }

        // Bomb out if handler returns true, since was able to render something to the client
        if ($isHandled) {
            exit;
        }

        // Rethrow to be handled by default php exception handling.
        throw $exception;
    }
643827
static function exceptionHandler($e) {
	    if(get_class($e) == 'PDOException'){
	        $err = $e->getMessage().'<br>code: '.$e->getCode();
	    } else {
	        $err = 
	        '<b>Code:</b>'.$e->getCode().'<br>'.
	        '<b>Message:</b> <i>'.$e->getMessage().'</i><br>'.
	        '<b>Thrown in: </b>'.$e->getFile().' ['.$e->getLine().']<br>'.
	        '<b>Stack trace:</b><pre>'.$e->getTraceAsString().'</pre>';
	        
	    }
	    exit($err);
	}
503407
protected void initializeExceptionHandler() {

        // Initialize the default uncaught exception handler for all other threads
        Thread.setDefaultUncaughtExceptionHandler(getDefaultUncaughtExceptionHandler());

        // Initialize the uncaught exception handler for JavaFX Application Thread
        JRebirth.runIntoJAT(ATTACH_JAT_UEH.getText(), () -> Thread.currentThread().setUncaughtExceptionHandler(getJatUncaughtExceptionHandler()));

        // Initialize the uncaught exception handler for JRebirth Internal Thread
        JRebirth.runIntoJIT(ATTACH_JIT_UEH.getText(), () -> Thread.currentThread().setUncaughtExceptionHandler(getJitUncaughtExceptionHandler()));
    }
694831
public function logException(\Exception $ex,$prefix="ex")
    {
        $this->log($ex->getCode().":".$ex->getMessage()."\r\n".$ex->getTraceAsString(),get_class($ex),$prefix);
    }
1262300
public function handleException($exception)
    {
        if (! $exception instanceof \Exception && ! $exception instanceof \Error) {
            $exception = new \Exception("Can't handle exception thrown!");
        }


        // Log
        \Logger::error((string) $exception);

        // Whoops
        if ($this->whoops !== false) {
            $this->whoops->handleException($exception);
        }
    }
1329586
protected function exception_handler($message, $throwException=false) {
		$logId = null;
		try {
			$this->lastException = $message;
			if(function_exists('cs_debug_backtrace')) {
				$message .= "\n\nBACKTRACE:::\n". cs_debug_backtrace(0);
			}
			$this->flogger($message);
			$logId = $this->do_log($message, 'exception in code');
			if($throwException === true) {
				//in this class, it is mostly useless to throw exceptions, so by default they're not thrown.
				throw new exception($message);
			}
		}
		catch(Exception $e) {
			$this->flogger($e->getMessage());
		}
		return($logId);
	}
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);
                }
            }
        }
    }
1168309
public function exception($exception)
    {
        try {
            foreach ($this->handlers as $handler) {
                $handler($exception);
            }
        } catch (\Throwable $e) {
            $msg = "Infinity loop in exception & error handler. \nMessage:\n" . $e;

            if ($this->app->get('system.debug')) {
                exit($msg);
            }

            exit($e->getMessage());
        }

        exit();
    }
751612
public function setErrorHandler()
    {
        set_error_handler(function ($errno, $errstr, $errfile, $errline ) {
            throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
        });
    }