本文整理汇总了PHP中Throwable::getTraceAsString方法的典型用法代码示例。如果您正苦于以下问题:PHP Throwable::getTraceAsString方法的具体用法?PHP Throwable::getTraceAsString怎么用?PHP Throwable::getTraceAsString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Throwable
的用法示例。
在下文中一共展示了Throwable::getTraceAsString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
/**
* @inheritDoc
*/
public function get()
{
if (!isset($this->throwable)) {
throw new LogicException('Throwable must be set to get view.');
}
ob_start();
var_dump($this->throwable->getTrace());
$fullTrace = ob_get_clean();
// If xdebug is installed then var_dump is pretty printed for html already.
if (function_exists('xdebug_var_dump')) {
$viewTrace = new Text();
$viewTrace->setHTML5($fullTrace);
$fullTrace = ['div', ['class' => 'full_trace'], $viewTrace->get()];
} else {
$fullTrace = ['pre', ['class' => 'full_trace'], $fullTrace];
}
return ['div', ['class' => 'Throwable'], [['div', ['class' => 'location'], 'Thrown at ' . $this->throwable->getFile() . ' line ' . $this->throwable->getLine()], ['pre', [], $this->throwable->getMessage()], ['h2', [], 'Basic Trace'], ['pre', ['class' => 'basic_trace'], $this->throwable->getTraceAsString()], ['h2', [], 'Full Trace'], $fullTrace]];
}
示例2: handle_exception
/**
* @param \Exception|\Throwable $exception
*/
public function handle_exception($exception)
{
if (getenv('APP_ENV') === 'dev') {
list($code, $file, $line, $message, $previous, $trace, $trace_string) = [$exception->getCode(), $exception->getFile(), $exception->getLine(), $exception->getMessage(), $exception->getPrevious(), $exception->getTrace(), $exception->getTraceAsString()];
$trace_info = "<b>file</b>: {$trace[0]['file']} <b>in line</b> ({$trace[0]['line']})";
echo "<h2>COGS Runtime Exception: [::{$code}] {$message}</h2>";
echo "<b>Trace:</b><br>";
echo "<pre>{$trace_string}</pre>";
echo "<b>Debug:</b><br>";
dump(compact('code', 'file', 'line', 'message', 'previous', 'trace'));
}
}
示例3: error
/**
* Return an error into an HTTP or JSON data array.
*
* @param string $title
* @return array
*/
public function error($title = null)
{
if ($title == null) {
$title = $this->debug ? 'The application could not run because of the following error:' : 'A website error has occurred. Sorry for the temporary inconvenience.';
}
$type = $this->request->getHeader('Content-Type');
$mesg = $this->exception->getMessage();
$file = $this->exception->getFile();
$line = $this->exception->getLine();
$code = $this->exception->getCode();
$statusCode = method_exists($this->exception, 'getStatusCode') ? $this->exception->getStatusCode() : null;
// Check status code is null
if ($statusCode == null) {
$statusCode = $code >= 100 && $code <= 500 ? $code : 400;
}
$this->response->withStatus($statusCode);
// Check logger exist
if ($this->logger !== null) {
// Send error to log
$this->logger->addError($this->exception->getMessage());
}
$this->isJson = isset($type[0]) && $type[0] == 'application/json';
// Check content-type is application/json
if ($this->isJson) {
// Define content-type to json
$this->response->withHeader('Content-Type', 'application/json');
$error = ['status' => 'error', 'status_code' => $statusCode, 'error' => $title, 'details' => []];
// Check debug
if ($this->debug) {
$error['details'] = ['message' => $mesg, 'file' => $file, 'line' => $line, 'code' => $code];
}
return $error;
}
// Define content-type to html
$this->response->withHeader('Content-Type', 'text/html');
$message = sprintf('<span>%s</span>', htmlentities($mesg));
$error = ['type' => get_class($this->exception), $error['status_code'] = $statusCode, 'message' => $message];
// Check debug
if ($this->debug) {
$trace = $this->exception->getTraceAsString();
$trace = sprintf('<pre>%s</pre>', htmlentities($trace));
$error['file'] = $file;
$error['line'] = $line;
$error['code'] = $code;
$error['trace'] = $trace;
}
$error['debug'] = $this->debug;
$error['title'] = $title;
return $error;
}
示例4: doRender
/**
* Render the error page for the given object
*
* @param \Throwable|\Exception $error The error object to be rendered
*
* @return string
*
* @since 4.0
*/
protected function doRender($error)
{
// Create our data object to be rendered
$data = ['error' => true, 'code' => $error->getCode(), 'message' => $error->getMessage()];
// Include the stack trace if in debug mode
if (JDEBUG) {
$data['trace'] = $error->getTraceAsString();
}
// Push the data object into the document
$this->getDocument()->setBuffer(json_encode($data));
if (ob_get_contents()) {
ob_end_clean();
}
return $this->getDocument()->render();
}
示例5: sendExceptionToEventJournal
/**
* @param \Exception|\Throwable $exception
* @param \Spryker\Shared\EventJournal\Model\EventJournalInterface $eventJournal
* @param \Spryker\Shared\NewRelic\ApiInterface $newRelicApi
* @param bool $ignoreInternalExceptions
*
* @return void
*/
protected static function sendExceptionToEventJournal($exception, EventJournalInterface $eventJournal, ApiInterface $newRelicApi, $ignoreInternalExceptions = false)
{
try {
$event = new Event();
$event->setField('message', $exception->getMessage());
$event->setField('trace', $exception->getTraceAsString());
$event->setField('class_name', get_class($exception));
$event->setField('file_name', $exception->getFile());
$event->setField('line', $exception->getLine());
$event->setField(Event::FIELD_NAME, 'exception');
self::addDeploymentInformation($event);
$eventJournal->saveEvent($event);
} catch (\Exception $internalException) {
if (!$ignoreInternalExceptions) {
self::sendExceptionToNewRelic($internalException, $eventJournal, $newRelicApi, true);
}
}
}
示例6: getErrorResponse
/**
* @param Exception|\Throwable $ex
*/
private static function getErrorResponse($ex)
{
$debugTrace = $ex->getTraceAsString();
$message = $ex->getMessage();
$isHtmlMessage = method_exists($ex, 'isHtmlMessage') && $ex->isHtmlMessage();
if (!$isHtmlMessage && Request::isApiRequest($_GET)) {
$outputFormat = strtolower(Common::getRequestVar('format', 'xml', 'string', $_GET + $_POST));
$response = new ResponseBuilder($outputFormat);
return $response->getResponseException($ex);
} elseif (!$isHtmlMessage) {
$message = Common::sanitizeInputValue($message);
}
$logo = new CustomLogo();
$logoHeaderUrl = false;
$logoFaviconUrl = false;
try {
$logoHeaderUrl = $logo->getHeaderLogoUrl();
$logoFaviconUrl = $logo->getPathUserFavicon();
} catch (Exception $ex) {
try {
Log::debug($ex);
} catch (\Exception $otherEx) {
// DI container may not be setup at this point
}
}
$result = Piwik_GetErrorMessagePage($message, $debugTrace, true, true, $logoHeaderUrl, $logoFaviconUrl);
try {
/**
* Triggered before a Piwik error page is displayed to the user.
*
* This event can be used to modify the content of the error page that is displayed when
* an exception is caught.
*
* @param string &$result The HTML of the error page.
* @param Exception $ex The Exception displayed in the error page.
*/
Piwik::postEvent('FrontController.modifyErrorPage', array(&$result, $ex));
} catch (ContainerDoesNotExistException $ex) {
// this can happen when an error occurs before the Piwik environment is created
}
return $result;
}
示例7: doRender
/**
* Render the error page for the given object
*
* @param \Throwable|\Exception $error The error object to be rendered
*
* @return string
*
* @since 4.0
*/
protected function doRender($error)
{
// Create our data object to be rendered
$xw = new \XMLWriter();
$xw->openMemory();
$xw->setIndent(true);
$xw->setIndentString("\t");
$xw->startDocument('1.0', 'UTF-8');
$xw->startElement('error');
$xw->writeElement('code', $error->getCode());
$xw->writeElement('message', $error->getMessage());
// Include the stack trace if in debug mode
if (JDEBUG) {
$xw->writeElement('trace', $error->getTraceAsString());
}
// End error element
$xw->endElement();
// Push the data object into the document
$this->getDocument()->setBuffer($xw->outputMemory(true));
if (ob_get_contents()) {
ob_end_clean();
}
return $this->getDocument()->render();
}
示例8: formatExceptionMessage
/**
* @param Exception|\Throwable $exception
* @return string
*/
private function formatExceptionMessage($exception)
{
$message = $exception->getMessage();
if (\Piwik_ShouldPrintBackTraceWithMessage()) {
$message .= "\n" . $exception->getTraceAsString();
}
return Renderer::formatValueXml($message);
}
示例9: exception
public function exception(\Throwable $throwable)
{
try {
if (@Application::getSettings()->logging->exceptions) {
$this->error('[EXCEPTION] ' . $throwable . PHP_EOL . $throwable->getTraceAsString());
}
} catch (SettingsException $throwable) {
// No setting present, throwable will not be logged.
}
}
示例10: exceptionStackTrace
/**
* @param \Throwable $exception
*
* @return array
*/
protected function exceptionStackTrace(\Throwable $exception) : array
{
$return = [];
$line = $exception->getLine();
$file = $exception->getFile();
$trace = $exception->getTrace();
foreach (explode("\n", $exception->getTraceAsString()) as $currentLine) {
$row = explode(' ', $currentLine);
$stack = ['file' => null];
$buffer = null;
$index = trim(array_shift($row), '#');
foreach ($row as $current) {
// current file
if (is_null($stack['file'])) {
if (substr($current, -1) === ':') {
$stack['file'] = trim($buffer ? $buffer . $current : $current, ':');
if (preg_match('`([^\\(]+)\\(([0-9]+)\\)`', $stack['file'], $matches)) {
$stack['file'] = $matches[1];
$stack['line'] = (int) $matches[2];
}
} else {
$buffer .= $current . ' ';
}
} elseif (!isset($stack['function'])) {
$stack['function'] = strstr($current, '(', true);
$explodeString = strpos($stack['function'], '::') !== false ? '::' : '->';
$explode = explode($explodeString, $stack['function']);
if (sizeof($explode) > 1) {
$stack['class'] = $explode[0];
$stack['type'] = $explodeString;
$stack['function'] = $explode[1];
if (strpos($stack['class'], '\\') !== false) {
$explode = explode('\\', $stack['class']);
$stack['class'] = array_pop($explode);
$stack['namespace'] = implode('\\', $explode);
}
} elseif (strpos($stack['function'], '\\') !== false) {
$explode = explode('\\', $stack['function']);
$stack['function'] = array_pop($explode);
$stack['namespace'] = implode('\\', $explode);
}
$stack['args'] = strstr($current, '(') . ' ';
} else {
$stack['args'] .= $current . ' ';
}
}
if (is_null($stack['file'])) {
$stack['file'] = $row[0];
}
$skip = false;
// hack to hide error handler
if (isset($stack['namespace']) && isset($stack['class'])) {
if ($stack['namespace'] == 'Cawa\\Error' && $stack['class'] == 'Handler') {
$skip = true;
}
}
// hack to hide backtrace call
if (isset($stack['function']) && $stack['function'] == 'backtrace') {
$skip = true;
$file = $stack['file'];
$line = (int) $stack['line'];
}
if ($skip == false) {
if (isset($trace[$index]) && isset($trace[$index]['args'])) {
$stack['fullargs'] = $trace[$index]['args'];
}
$return[] = $stack;
}
}
$return[0]['line'] = $line;
$return[0]['file'] = $file;
return $return;
}
示例11: buildStackTraceString
public static function buildStackTraceString(\Throwable $t)
{
return '#t ' . $t->getFile() . ' (' . $t->getLine() . ')' . "\r\n" . $t->getTraceAsString();
}
示例12: getTrace
private function getTrace() : string
{
return '<pre>' . $this->throwable->getTraceAsString() . '</pre>';
}
示例13: onException
/**
* Обработка ошибки
* @param Throwable $e
* @return mixed
*/
public static function onException($e)
{
if (APPLICATION_ENV == 'production' && ($e->getCode() >= 500 || $e->getCode() == 0) && isset(Boot::getInstance()->config->mail->error)) {
self::send(Boot::getInstance()->config->mail->error, "Error", "<pre>Error " . $e->getCode() . ": " . $e->getMessage() . "\r\n" . $e->getTraceAsString() . "SERVER:\r\n" . var_export($_SERVER, true) . "POST:\r\n" . var_export($_POST, true) . "</pre>");
}
}
示例14: printException
/**
* @param \Throwable|\Exception $e
*/
private function printException($e)
{
echo 'Exception: ' . $e->getMessage() . ' (' . $e->getFile() . ':' . $e->getLine() . ")\n";
echo $e->getTraceAsString() . "\n";
}
示例15: getResponseFormat
/**
* Method that returns a response in the request format
*
* @todo Customize according to project
* @param string $message Error message
* @param int $status Status code
* @param \Exception $exception Exception caught
* @return JsonResponse|HtmlResponse
*/
public function getResponseFormat($message, $status, \Throwable $exception)
{
if (count($this->accept) > 0 && $this->accept[0] == 'application/json') {
$data = ['status' => $status, 'error' => ['msg' => $message]];
if ($this->debug) {
$data['error']['debug']['msg'] = $exception->getMessage();
$data['error']['debug']['file'] = $exception->getFile();
$data['error']['debug']['line'] = $exception->getLine();
$data['error']['debug']['trace'] = $exception->getTrace();
}
return new JsonResponse($data, $status);
}
$msg = $message;
if ($this->debug) {
$msg .= '<br />Description: ' . $exception->getMessage();
$msg .= '<br />File: ' . $exception->getFile();
$msg .= '<br />Line: ' . $exception->getLine();
$msg .= '<br />Trace: ' . $exception->getTraceAsString();
}
return new HtmlResponse($msg, $status);
}