本文整理汇总了PHP中Exception::getTrace方法的典型用法代码示例。如果您正苦于以下问题:PHP Exception::getTrace方法的具体用法?PHP Exception::getTrace怎么用?PHP Exception::getTrace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Exception
的用法示例。
在下文中一共展示了Exception::getTrace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getExceptionTraceAsString
/**
* @param \Exception $exception
* @return string
* @todo Fix this to get full stack trace
*/
public static function getExceptionTraceAsString(\Exception $exception)
{
$ret = "";
$count = 0;
foreach ($exception->getTrace() as $trace) {
$args = "";
if (isset($trace['args'])) {
$args = array();
foreach ($trace['args'] as $arg) {
if (is_string($arg)) {
$args[] = "'" . $arg . "'";
} elseif (is_array($arg)) {
$args[] = "Array";
} elseif (is_null($arg)) {
$args[] = 'NULL';
} elseif (is_bool($arg)) {
$args[] = $arg ? "true" : "false";
} elseif (is_object($arg)) {
$args[] = get_class($arg);
} elseif (is_resource($arg)) {
$args[] = get_resource_type($arg);
} else {
$args[] = $arg;
}
}
$args = join(", ", $args);
}
$ret .= sprintf("#%s %s(%s): %s(%s)\n", $count, isset($trace['file']) ? $trace['file'] : 'unknown file', isset($trace['line']) ? $trace['line'] : 'unknown line', isset($trace['class']) ? $trace['class'] . $trace['type'] . $trace['function'] : $trace['function'], $args);
$count++;
}
return $ret;
}
示例2: afterAction
/**
* After action.
*
* @param \CInlineAction $action Action from controller
*
* @return \Docolight\Http\Response
*/
public function afterAction($action)
{
parent::afterAction($action);
// Basic data template
$statusCode = 200;
$data = array('status' => $statusCode, 'message' => 'Success', 'value' => $this->data);
// Let's find an error
if ($this->error instanceof Exception) {
// throw $this->error;
// Basic data template for an exception
$statusCode = 500;
$data = ['status' => $statusCode, 'message' => 'Error', 'value' => ['code' => $this->error->getCode(), 'message' => $this->error->getMessage()]];
// If exception code is an HTTP resoponse code
if ($message = Response::getMessageForCode($this->error->getCode())) {
$statusCode = $this->error->getCode();
$data['status'] = $statusCode;
$data['message'] = preg_replace('/^\\d+ /', '', $message);
} else {
if (YII_DEBUG) {
$data['value']['stack_trace'] = $this->error->getTrace();
}
}
} elseif ($this->data instanceof Response) {
return $this->data->send();
}
return response('json', $statusCode, collect($data), $this->headers)->send();
}
示例3: getFrames
/**
* Returns an iterator for the inspected exception's frames.
*
* @return FrameCollection
*/
public function getFrames()
{
if ($this->frames === null) {
$frames = $this->exception->getTrace();
// If we're handling an \ErrorException thrown by BooBoo,
// get rid of the last frame, which matches the handleError method,
// and do not add the current exception to trace. We ensure that
// the next frame does have a filename / linenumber, though.
if ($this->exception instanceof \ErrorException) {
foreach ($frames as $k => $frame) {
if (isset($frame['class']) && strpos($frame['class'], 'BooBoo') !== false) {
unset($frames[$k]);
}
}
}
$this->frames = new FrameCollection($frames);
if ($previousInspector = $this->getPreviousExceptionInspector()) {
// Keep outer frame on top of the inner one
$outerFrames = $this->frames;
$newFrames = clone $previousInspector->getFrames();
$newFrames->prependFrames($outerFrames->topDiff($newFrames));
$this->frames = $newFrames;
}
}
return $this->frames;
}
示例4: handleException
public function handleException(Exception $exception)
{
$msg = "Uncaught Exception: " . $exception->getMessage() . "\n";
$msg .= $exception->getMessage() . "\n";
$msg .= 'Line: ' . $exception->getLine() . " in " . $exception->getFile();
$msg .= "\n\nTrace Summary:\n" . self::traceFormat($exception->getTrace());
if (ERROR_DISPLAY_MODE == 'html') {
$msg .= "\nFull Trace: \n" . print_r($exception->getTrace(), 1);
}
$this->show($msg, $exception->getFile(), $exception->getLine(), $exception->getCode(), 'E_WARNING');
}
示例5: assertEquals
/**
*
* @param mixed $expected
* @param mixed $got
* @param string $message
*/
public function assertEquals($expected, $got, $message = '')
{
$e = new Exception();
$trace = $e->getTrace()[1];
$line = $e->getTrace()[0]['line'];
if ($expected !== $got) {
echo sprintf(PHP_EOL . '# ASSERTION ERROR: %s::%s (%s) %s' . PHP_EOL . 'expected:%s' . PHP_EOL . 'got:%s' . PHP_EOL, $trace['class'], $trace['function'], $line, $message, var_export($expected, true), var_export($got, true));
} else {
echo '.';
}
}
示例6: getFilteredStacktrace
/**
* Filters stack frames from PHPUnit classes.
*
* @param Exception $e
* @param boolean $filterTests
* @param boolean $asString
* @return string
*/
public static function getFilteredStacktrace(Exception $e, $filterTests = TRUE, $asString = TRUE)
{
if ($asString === TRUE) {
$filteredStacktrace = '';
} else {
$filteredStacktrace = array();
}
$groups = array('DEFAULT');
if (!defined('PHPUNIT_TESTSUITE')) {
$groups[] = 'PHPUNIT';
}
if ($filterTests) {
$groups[] = 'TESTS';
}
if ($e instanceof PHPUnit_Framework_SyntheticError) {
$eTrace = $e->getSyntheticTrace();
} else {
$eTrace = $e->getTrace();
}
if (!self::frameExists($eTrace, $e->getFile(), $e->getLine())) {
array_unshift($eTrace, array('file' => $e->getFile(), 'line' => $e->getLine()));
}
foreach ($eTrace as $frame) {
if (isset($frame['file']) && is_file($frame['file']) && !PHP_CodeCoverage::getInstance()->filter()->isFiltered($frame['file'], $groups, TRUE)) {
if ($asString === TRUE) {
$filteredStacktrace .= sprintf("%s:%s\n", $frame['file'], isset($frame['line']) ? $frame['line'] : '?');
} else {
$filteredStacktrace[] = $frame;
}
}
}
return $filteredStacktrace;
}
示例7: exceptionHandler
public static function exceptionHandler(\Exception $e)
{
$fullTrace = $e->getTrace();
if (is_callable(array($e, 'postAction'))) {
$e->postAction($e->getMessage(), $e->getCode());
}
if (!DC::getProjectConfig('devMode')) {
DC::getLogger()->add('Exception: ' . $e->getMessage(), 'exception');
die;
}
$content = '<div style="font-size: 13px; font-family: Consolas, Menlo, Monaco, monospace;white-space: pre-wrap;">';
$htmlTrace = "<b>\nLast arguments(" . count($fullTrace[0]['args']) . "):</b>\n" . dumpAsString($fullTrace[0]['args']) . "<b>\n\nCall stack:</b>\n<table style='font-size: 13px;'>";
foreach ($fullTrace as $item) {
$info = self::compileShortCallee($item);
$htmlTrace .= '<tr><td style="color:#666;padding-right:10px;">' . $info['file'] . '</td><td>' . $info['call'] . '</td></tr>';
}
$htmlTrace .= '</table>';
$content .= '<div style="background:#c00;color:white;font-weight:bold;padding:5px;margin-bottom: 5px; ">' . $e->getMessage() . '</div>';
$content .= $htmlTrace;
$content .= '</div>';
if (DC::getRouter()->getExecutionMode() == Request::MODE_CONSOLE) {
$content = strip_tags(str_replace('</td><td>', "\n", $content)) . "\n";
}
echo $content;
die;
}
示例8: testNew
public function testNew()
{
$ex = new \Exception();
$traces = $ex->getTrace();
$t = new Trace($traces[0]);
$this->AssertSame($t->class, 'BetterErrorTests\\TraceTest');
}
示例9: displayExceptionObject
function displayExceptionObject(Exception $e)
{
echo "\$e = >{$e}<\n";
// calls __toString
echo "getMessage: >" . $e->getMessage() . "<\n";
echo "getCode: >" . $e->getCode() . "<\n";
echo "getPrevious: >" . $e->getPrevious() . "<\n";
echo "getFile: >" . $e->getFile() . "<\n";
echo "getLine: >" . $e->getLine() . "<\n";
echo "getTraceAsString: >" . $e->getTraceAsString() . "<\n";
$traceInfo = $e->getTrace();
var_dump($traceInfo);
echo "Trace Info:" . (count($traceInfo) == 0 ? " none\n" : "\n");
foreach ($traceInfo as $traceInfoKey => $traceLevel) {
echo "Key[{$traceInfoKey}]:\n";
foreach ($traceLevel as $levelKey => $levelVal) {
if ($levelKey != "args") {
echo " Key[{$levelKey}] => >{$levelVal}<\n";
} else {
echo " Key[{$levelKey}]:\n";
foreach ($levelVal as $argKey => $argVal) {
echo " Key[{$argKey}] => >{$argVal}<\n";
}
}
}
}
}
示例10: _processTrace
/**
* @param Exception $exception
* @param Report $report
*/
protected function _processTrace(Report $report)
{
foreach ($this->exception->getTrace() as $t) {
$aeTrace = new Traceback();
$aeTrace->setFile(isset($t['file']) ? $t['file'] : 'unknown');
$aeTrace->setFn(isset($t['class']) ? "{$t['class']}->{$t['function']}" : $t['function']);
$aeTrace->setLine(isset($t['line']) ? $t['line'] : 0);
$aeArgs = array();
foreach ($t['args'] as $arg) {
$aeArgs[] = $arg;
}
$aeTrace->setVars(json_encode($aeArgs));
$report->addTraceback($aeTrace);
unset($aeTrace);
}
}
示例11: __call
/**
* Ставим хук на вызов неизвестного метода и считаем что хотели вызвать метод какого либо модуля
* @see Engine::_CallModule
*
* @param $sName
* @param $aArgs
*
* @return mixed
* @throws Exception
*/
public function __call($sName, $aArgs)
{
// Ввзовом метода модуля считаем, если есть подчеркивание и оно не в начале
if (strpos($sName, '_')) {
return E::getInstance()->_CallModule($sName, $aArgs);
} else {
// Если подчеркивания нет, то вызов несуществующего метода
$oException = new Exception('Method "' . $sName . '" not exists in class "' . get_class($this) . '"');
$aStack = $oException->getTrace();
if (!$aStack) {
$aStack = debug_backtrace();
}
// Инвертируем стек вызовов
$aStack = array_reverse($aStack);
// И пытаемся определить, откуда был этот некорректный вызов
foreach ($aStack as $aCaller) {
if (isset($aCaller['file']) && isset($aCaller['function'])) {
if (preg_match('/[A-Z]\\w+\\_' . preg_quote($sName) . '/', $aCaller['function']) || $aCaller['function'] == $sName) {
$oException->sAdditionalInfo = 'In file ' . $aCaller['file'];
if (isset($aCaller['line'])) {
$oException->sAdditionalInfo .= ' on line ' . $aCaller['line'];
}
break;
}
}
}
throw $oException;
}
}
示例12: getExceptionTraceAsString
function getExceptionTraceAsString(Exception $exception)
{
$rtn = "";
$count = 0;
foreach ($exception->getTrace() as $frame) {
$args = "";
if (isset($frame['args'])) {
$args = array();
foreach ($frame['args'] as $arg) {
if (is_string($arg)) {
$args[] = "'" . $arg . "'";
} elseif (is_array($arg)) {
$args[] = json_encode($arg);
} elseif (is_null($arg)) {
$args[] = 'NULL';
} elseif (is_bool($arg)) {
$args[] = $arg ? "true" : "false";
} elseif (is_object($arg)) {
$args[] = get_class($arg);
} elseif (is_resource($arg)) {
$args[] = get_resource_type($arg);
} else {
$args[] = $arg;
}
}
$args = join(", ", $args);
}
$rtn .= sprintf("#%s %s(%s): %s%s(%s)\n", $count, $frame['file'], $frame['line'], isset($frame['class']) ? $frame['class'] . '->' : '', $frame['function'], $args);
$count++;
}
return $rtn;
}
示例13: catchException
/**
*
* @param Exception $exception
*/
public static function catchException($exception)
{
$code = $exception->getCode();
$errorController = 'app\\controllers\\ErrorController';
$result = ClassLoader::load($errorController, false);
if ($result && class_exists($errorController)) {
$controllerObj = new $errorController(new \radium\net\http\Request());
$action = 'index';
$controllerObj->_render['template'] = $action;
$controllerObj->invokeMethod('_init');
$data = call_user_func_array(array($controllerObj, $action), array($exception));
$contentType = 'text/html';
$output = '';
if (is_string($data)) {
$output = $data;
$contentType = 'text/plain';
} else {
$controllerObj->invokeMethod('_finalize', $data ? array($data) : array());
$output = $controllerObj->renderedContent();
$contentType = $controllerObj->view->contentType();
}
header('Content-Type: ' . $contentType . '; charset=UTF-8');
echo $output;
exit;
}
$backtrace = $exception->getTrace();
$line = array_shift($backtrace);
while ($line && !isset($line['file'])) {
$line = array_shift($backtrace);
}
header('Content-Type: text/plain; charset=UTF-8');
echo StringUtil::getLocalizedString('Exception was thrown. ({1}): {2} at {3} line {4} ({5} line {6})', array($code, $exception->getMessage(), $line['file'], $line['line'], $exception->getFile(), $exception->getLine())) . "\n";
exit;
}
示例14: handle
/**
* Sends a response for the given Exception.
*
* If you have the Symfony HttpFoundation component installed,
* this method will use it to create and send the response. If not,
* it will fallback to plain PHP functions.
*
* @param \Exception $exception An \Exception instance
*
* @see sendPhpResponse
* @see createResponse
*/
public function handle(\Exception $exception)
{
if ($this->logger !== null) {
$this->logger->error($exception->getMessage());
}
if ($this->logger_trace !== null) {
$string = $exception->getMessage() . "\r\n";
foreach ($exception->getTrace() as $trace) {
$string .= ' ';
if (isset($trace['file'])) {
$string .= 'at ' . $trace['file'] . '(' . $trace['line'] . ') ';
}
if (isset($trace['class'])) {
$string .= 'in ' . $trace['class'] . $trace['type'];
}
if (isset($trace['function'])) {
$string .= $trace['function'] . '(' . $this->stringify($trace['args']) . ')';
}
$string .= "\r\n";
}
$this->logger_trace->error($string);
}
if (class_exists('Symfony\\Component\\HttpFoundation\\Response')) {
$this->createResponse($exception)->send();
} else {
$this->sendPhpResponse($exception);
}
}
示例15: exception_handler
/**
* Handle uncaught exceptions.
*
* @param \Exception $exception An uncaught exception.
*/
public static function exception_handler(\Exception $exception)
{
global $CFG, $USR;
$errcode = $exception->getCode();
$errmsg = $exception->getMessage();
$errcodelabel = $exception instanceof \pdyn\base\Exception ? $exception->get_string_from_code($errcode) : static::getinternalerrorlabel($errcode);
if (\pdyn\base\Utils::is_cli_env() === true) {
echo 'APP ERROR: ' . $errcodelabel . ': ' . $errmsg . "\n";
} else {
// Atlas exceptions' error codes are HTTP status codes, so send one.
if ($exception instanceof \pdyn\base\Exception && !empty($errcode) && !headers_sent()) {
\pdyn\httputils\Utils::send_status_code($errcode, '', false);
} else {
\pdyn\httputils\Utils::send_status_code(500, '', false);
}
$LOG = new \pdyn\log\Logger($CFG->log_general);
$LOG->error($errcodelabel . ': ' . $exception);
if (isset($_GET['ajax'])) {
header('Content-type: application/json');
echo json_encode(['result' => 'fail', 'msg' => $errcodelabel . ': ' . $errmsg]);
} else {
$debugmode = !empty($CFG) && (bool) $CFG->get('core', 'debugmode', false) === true ? true : false;
$isadmin = !empty($USR) && $USR->is_admin === true ? true : false;
$backtrace = $isadmin === true || $debugmode === true ? static::format_backtrace($exception->getTrace()) : null;
static::write_error_html($errcodelabel, $errmsg, $errcode, $backtrace);
}
}
die;
}