The __toString method isn't allowed to throw exceptions so we turn them into an error instead.

@param \Exception $e

@return string
196912
private function handleException(\Exception $e)
    {
        trigger_error($e->getMessage() . "\n" . $e->getTraceAsString(), E_USER_WARNING);
        if ($e instanceof Error) {
            return '<strong>' . $e->getRawMessage() . '</strong>';
        }

        return '';
    }
612524
public static function extErrorMessage($e)
    {
        if ($e instanceof Exception\CMS) {
            return $e->getExtMessage();
        } else {
            return 'In file <b>'.$e->getFile().'</b> on line: '.$e->getLine()."<br /><br /><b>Stack trace:</b><br />".nl2br($e->getTraceAsString());
        }
    }
924168
public function writeException(\Exception $e)
    {
        if ($this->verboseException) {
            $text = sprintf("[%s]\n%s\nIn %s at line %s\n%s", 
                get_class($e),
                $e->getMessage(),
                $e->getFile(),
                $e->getLine(),
                $e->getTraceAsString()
            );
        } else {
            $text = sprintf("\n[%s]\n%s\n", get_class($e), $e->getMessage());
        }

        $box = new Widgets\Box($this->textWriter, $text, '');
        $out = Colors::colorizeLines($box, Colors::WHITE, Colors::RED);
        $out = TextFormater::apply($out, array('indent' => 2));
        $this->textWriter->writeln($out);
        return $this;
    }
960364
protected function generateExceptionResponse(Exception $e){

        $e = FlattenException::create($e);
        $content = $this->decoreate($this->exceptionHandler->getContent($e), $this->exceptionHandler->getStylesheet($e), 'utf-8');

        return response($content, 500);
    }
1206189
public static function convertExceptionToString($exception)
    {
        if ($exception instanceof Exception && ($exception instanceof UserException || !YII_DEBUG)) {
            $message = "{$exception->getName()}: {$exception->getMessage()}";
        } elseif (YII_DEBUG) {
            if ($exception instanceof Exception) {
                $message = "Exception ({$exception->getName()})";
            } elseif ($exception instanceof ErrorException) {
                $message = "{$exception->getName()}";
            } else {
                $message = 'Exception';
            }
            $message .= " '" . get_class($exception) . "' with message '{$exception->getMessage()}' \n\nin "
                . $exception->getFile() . ':' . $exception->getLine() . "\n\n"
                . "Stack trace:\n" . $exception->getTraceAsString();
        } else {
            $message = 'Error: ' . $exception->getMessage();
        }
        return $message;
    }
1285459
private function _exceptionHandler($e)
    {
        $this->_errorController->setParams(array('e' => $e));
        $action = FrontController::EXCEPTION_HANDLER_ACTION . 'Action';
        $this->_response->setStatusCode(500);

        return $this->_errorController->$action();
    }
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;
	}
63891
protected function transformMediaUploadException(Exception $e)
    {
        if ($e instanceof MediaUploadException) {
            $status_code = $this->getStatusCodeForMediaUploadException($e);
            return new HttpException($status_code, $e->getMessage(), $e);
        }

        return $e;
    }
947582
protected function convertExceptionToArray(Exception $e)
    {
        return $this->container->make('config')->get('app.debug') ? [
            'message' => $e->getMessage(),
            'exception' => get_class($e),
            'file' => $e->getFile(),
            'line' => $e->getLine(),
            'trace' => collect($e->getTrace())->map(function ($trace) {
                return Arr::except($trace, ['args']);
            })->all(),
        ] : [
            'message' => $this->isServiceException($e) ? $e->getMessage() : 'Server Error',
        ];
    }
98877
protected function internalError(Exception $e)
    {
        if (isset($this->hooks['internal.error'])) {
            return $this->hooks['internal.error']($e);
        } else {
            return (new Response())
                ->setStatusCode(500)
                ->setBody('Internal error: ' . $e->getMessage());
        }
    }
225836
public function formatException(\Exception $e) {
        $entry = array();

        $entry['class'] = get_class($e);
        $entry['message'] = $e->getMessage();
        $entry['file'] = $e->getFile();
        $entry['line'] = $e->getLine();
        $entry['trace'] = $e->getTraceAsString();

        return $entry;
    }
772740
private function convertException(Exception $e)
    {
        $data = [];
        $data['message']  = $e->getMessage();
        $data['code']     = $e->getCode();
        $data['trace']    = $this->filterTrace($e->getTrace());
        $data['status']   = Response::HTTP_INTERNAL_SERVER_ERROR;

        // determine the relevant file
        $firstTraceEntry = !empty($data['trace']) ? reset($data['trace']) : null;
        if ($firstTraceEntry !== null && isset($firstTraceEntry['file']) && isset($firstTraceEntry['line'])) {
            $data['file'] = $firstTraceEntry['file'];
            $data['line'] = $firstTraceEntry['line'];
        }
        else {
            $data['file'] = $e->getFile();
            $data['line'] = $e->getLine();
        }

        if ($e instanceof HttpException) {
            $data['status'] = $e->getStatusCode() ?: Response::HTTP_INTERNAL_SERVER_ERROR;
        }
        else if ($e instanceof QueryException) {
            $data['ansiCode']   = isset($e->errorInfo[0]) ? $e->errorInfo[0] : null;
            $data['driverCode'] = isset($e->errorInfo[1]) ? $e->errorInfo[1] : null;
            if (!empty($e->errorInfo[2])) {
                $data['message'] = $e->errorInfo[2];
            }
            $data['sql'] = $e->getDump();
        }

        return $data;
    }
1102825
public function record(Exception $e)
    {
        $this->exception = $e;
        return $this->recorder->record($e);
    }
506024
public static function exception_handler(\Exception $e)
	{
		if (method_exists($e, 'handle'))
		{
			return $e->handle();
		}

		$severity = ( ! isset(static::$levels[$e->getCode()])) ? $e->getCode() : static::$levels[$e->getCode()];
		logger(\Fuel::L_ERROR, $severity.' - '.$e->getMessage().' in '.$e->getFile().' on line '.$e->getLine());

		if (\Fuel::$env != \Fuel::PRODUCTION)
		{
			static::show_php_error($e);
		}
		else
		{
			static::show_production_error($e);
		}
	}
340649
public function handleException($e)
    {
        if (!$e instanceof Exception) { // Since PHP 7, in addition to an Exception, an internal Error may occur.
            // Convert the Error to ErrorException
            $e = new ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine()); // @codeCoverageIgnore
        } // @codeCoverageIgnore

        $this->getExceptionHandler()->handle($e);
    }
18198
protected function handleHttpException(Exception $e)
    {
        $statusCode = $e->getStatusCode();

        // if there is no exception message just get the standard HTTP text.
        if (empty($e->getMessage())) {
            $message = Response::$statusTexts[$statusCode];
        } else {
            $message = $e->getMessage();
        }

        return $this->generateResponse('', null, $statusCode, Status::FAIL, $message);
    }
896310
public static function fromException(\Exception $e)
    {
        if ($e instanceof XsollaWebhookException) {
            return static::fromErrorCode($e->getXsollaErrorCode(), $e->getMessage(), $e->getHttpStatusCode());
        } else {
            return static::fromErrorCode('FATAL_ERROR', $e->getMessage());
        }
    }