Exception Handler

Do not call this method directly. Function visibility is public because set_exception_handler does not allow for
protected method callbacks.

@param  object $exception  The exception to be handled
@return bool
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;
    }
759355
function exceptionHandler($Exception)
    {
    
        $this->inExceptionHandler = true;
    
        header('HTTP/1.1 500 Internal Server Error');
    
        try {
            $this->fb($Exception);
        } catch (Exception $e) {
            echo 'We had an exception: ' . $e;
        }
        $this->inExceptionHandler = false;
    }
584665
public function exceptionHandler($exception) {
		try {
			// load errorhandler
			$debug = Factory::load('Debug');
			$debug->errorhandler($exception);
		} catch (\Exception $e) {
			echo "<pre>$exception</pre>\n\n";

			// useful if the \Exception handler itself contains errors
			echo "<pre>The Debug class threw an exception:\n$e</pre>";
		}
	}
1193982
protected static function isDeveloperPresentable($exception)
    {
        if(class_exists(ExceptionHandler::class)) {
            return ExceptionHandler::isDeveloperPresentableException($exception);
        }

        return isset($exception->isDeveloperPresentable) ? $exception->isDeveloperPresentable : true;
    }
816194
public static function exception( $exception ) 
	{
		// clean the main output buffer
		while ( ob_get_level() > 0 ) 
		{
			ob_end_clean();
		}
		
		$error_handler = "\\".CCCORE_NAMESPACE."\\CCError_Handler".( ClanCats::is_cli() ? '_Cli' : '' );
		$error_inspector = "\\".CCCORE_NAMESPACE."\\CCError_Inspector";
		
		if ( is_object( ClanCats::$config ) && ClanCats::$config instanceof CCConfig ) 
		{
			$error_handler = ClanCats::$config->get( 'error.'.( ClanCats::is_cli() ? 'cli_' : '' ).'handler', $error_handler );
			$error_inspector = ClanCats::$config->get( 'error.inspector', $error_inspector );
		}
		
		$inspector = new $error_inspector( $exception );
		
		$handler = new $error_handler( $inspector );
		
		$handler->handle();
	}
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();
    }
547142
protected function sendExceptionToSentry($exception)
    {
        if (!Bootstrap::$staticObjectManager instanceof ObjectManagerInterface) {
            return;
        }

        $options = $this->resolveCustomRenderingOptions($exception);
        if (isset($options['logException']) && $options['logException']) {
            try {
                /** @var ErrorHandler $errorHandler */
                $errorHandler = Bootstrap::$staticObjectManager->get(ErrorHandler::class);
                if ($errorHandler !== null) {
                    $errorHandler->handleException($exception);
                }
            } catch (\Exception $exception) {
                // Quick'n dirty workaround to catch exception with the error handler is called during compile time
            }
        }
    }
1247108
public function catchException($exception)
    {
        if (in_array(get_class($exception), $this->config->getExcludeExceptions())) {
            return;
        }

        try {
            $this->send(
                Formatter::make($exception, $this->config)->toArray()
            );
        } catch (Exception $exception) {
            error_log('AfterBug Error: Couldn\'t notify. '.$exception->getMessage());
        }
    }
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;
    }
251360
final protected function handleErrors($exception = null)
    {
        $errorInfo = [
            'code' => 0,
            'message' => null,
            'file' => null,
            'line' => null,
            'trace' => null,
            'exception' => null,
        ];
        if ($exception instanceof \Throwable ||
            $exception instanceof \Exception
        ) {
            $errorInfo['code'] = $exception->getCode();
            $errorInfo['message'] = $exception->getMessage();
            $errorInfo['file'] = $exception->getFile();
            $errorInfo['line'] = $exception->getLine();
            $errorInfo['trace'] = $exception->getTrace();
            $errorInfo['exception'] = $exception;
        } else {
            $last_error = error_get_last();
            if (!empty($last_error['message'])) {
                $errorInfo['message'] = $last_error['message'];
            }
            if (!empty($last_error['file'])) {
                $errorInfo['file'] = $last_error['file'];
            }
            if (!empty($last_error['line'])) {
                $errorInfo['line'] = $last_error['line'];
            }
        }
        if (!empty($errorInfo['message'])) {
            return $this->halt($errorInfo);
        }
        return false;
    }
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);
        }
    }
838466
public function api_exception_handler( $exception ) {
		// If we have a verbose exception
		if ( $exception instanceOf ApiVerboseException ) {
			$more_info = $exception->getMoreInfo();
		}
		else {
			$more_info = null;
		}

		// Let's handle the exception gracefully
		$this->abort(
			$exception->getCode(),
			$exception->getSlug(), // ApiException interface method
			$exception->getMessage(),
			$more_info
		);
	}
1254212
public static function handleException(\Exception $exception) {
        $context = [];
        $second  = null;

        try {
            $context['class'    ] = __CLASS__;
            $context['file'     ] = $exception->getFile();  // If the location is not preset the logger will resolve the
            $context['line'     ] = $exception->getLine();  // exception handler as the originating location.
            $context['unhandled'] = true;

            Logger::log($exception, L_FATAL, $context);     // log with the highest level
        }

        // Exceptions thrown from within the exception handler will not be passed back to the handler again. Instead the
        // script terminates with an uncatchable fatal error.
        catch (\Exception $second) {
            $indent = ' ';                                  // the application is crashing, last try to log

            // secondary exception
            $msg2  = '[FATAL] Unhandled '.trim(DebugHelper::composeBetterMessage($second)).NL;
            $file  = $second->getFile();
            $line  = $second->getLine();
            $msg2 .= $indent.'in '.$file.' on line '.$line.NL.NL;
            $msg2 .= $indent.'Stacktrace:'.NL.$indent.'-----------'.NL;
            $msg2 .= DebugHelper::getBetterTraceAsString($second, $indent);

            // primary (the causing) exception
            if (isset($context['cliMessage'])) {
                $msg1 = $context['cliMessage'];
                if (isset($context['cliExtra']))
                    $msg1 .= $context['cliExtra'];
            }
            else {
                $msg1  = $indent.'Unhandled '.trim(DebugHelper::composeBetterMessage($exception)).NL;
                $file  = $exception->getFile();
                $line  = $exception->getLine();
                $msg1 .= $indent.'in '.$file.' on line '.$line.NL.NL;
                $msg1 .= $indent.'Stacktrace:'.NL.$indent.'-----------'.NL;
                $msg1 .= DebugHelper::getBetterTraceAsString($exception, $indent);
            }

            $msg  = $msg2.NL;
            $msg .= $indent.'caused by'.NL;
            $msg .= $msg1;
            $msg  = str_replace(chr(0), '?', $msg);         // replace NUL bytes which mess up the logfile

            if (CLI)                                        // full second exception
                echo $msg.NL;
            error_log(trim($msg), ERROR_LOG_DEFAULT);
        }

        // web: prevent an empty page
        if (!CLI) {
            try {
                if (Application::isAdminIP() || ini_get_bool('display_errors')) {
                    if ($second) {                          // full second exception, full log location
                        echoPre($second);
                        echoPre('error log: '.(strlen($errorLog=ini_get('error_log')) ? $errorLog : 'web server'));
                    }
                }
                else echoPre('application error (see error log)');
            }
            catch (\Exception $third) {
                echoPre('application error (see error log)');
            }
        }
    }
1078728
public function wrapAndHandleException($exception)
    {
        if ($exception instanceof Error) {
            $exception = new Exception($exception);
        }

        $this->handleException($exception);
    }
1206785
public static function onException( $exception )
    {
        $_trace = $exception->getTrace();
        $_traceText = static::_cleanTrace( $_trace, 3 );

        if ( E_NOTICE == $exception->getCode() )
        {
            return false;
        }

        static::$_error = array(
            'code'       => $exception->getCode(),
            'type'       => '',
            'message'    => $exception->getMessage(),
            'file'       => $exception->getFile(),
            'line'       => $exception->getLine(),
            'trace'      => $_traceText,
            'traces'     => $exception->getTrace(),
            'source'     => static::_getCodeLines( $exception->getFile(), $exception->getLine(), static::$_sourceLines ),
            'start_line' => static::$_startLine,
        );

        Log::error( static::$_error['message'] . ' (' . static::$_error['code'] . ')' );

        return static::renderError();
    }
31983
public function exceptionHandler($exception)
    {
        $this->lastHandledException = $exception;

        $this->client->catchException($exception);

        if ($this->oldExceptionHandler) {
            call_user_func(
                $this->oldExceptionHandler,
                $exception
            );
        }
    }
1339336
public function setExceptionHandler(callable $handler = null)
    {
        $prev = $this->exceptionHandler;
        $this->exceptionHandler = $handler;

        return $prev;
    }