本文整理汇总了PHP中Exception::getPrevious方法的典型用法代码示例。如果您正苦于以下问题:PHP Exception::getPrevious方法的具体用法?PHP Exception::getPrevious怎么用?PHP Exception::getPrevious使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Exception
的用法示例。
在下文中一共展示了Exception::getPrevious方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: displayError
/**
* handle errors
*
* @param \Exception $error the error stack
* @param Symfony\Component\Console\Output\OutputInterface $output the ooutput interface
* @param string $prefix the prefix to indent the text
*/
protected function displayError(\Exception $error, OutputInterface $output, $prefix = '')
{
$output->writeln('<error>' . $prefix . $error->getMessage() . '</error>');
if ($error->getPrevious()) {
$this->displayError($error->getPrevious(), $output, "\t - ");
}
}
示例2: getFilteredStackTrace
public static function getFilteredStackTrace(Exception $e, $asString = true)
{
$stackTrace = $asString ? '' : array();
$trace = $e->getPrevious() ? $e->getPrevious()->getTrace() : $e->getTrace();
if ($e instanceof \PHPUnit_Framework_ExceptionWrapper) {
$trace = $e->getSerializableTrace();
}
foreach ($trace as $step) {
if (self::classIsFiltered($step)) {
continue;
}
if (self::fileIsFiltered($step)) {
continue;
}
if (!$asString) {
$stackTrace[] = $step;
continue;
}
if (!isset($step['file'])) {
continue;
}
$stackTrace .= $step['file'] . ':' . $step['line'] . "\n";
}
return $stackTrace;
}
示例3: exceptionToArray
public static function exceptionToArray(\Exception $e)
{
$a = array('code' => $e->getCode(), 'message' => $e->getMessage());
if ($e->getPrevious() !== null) {
$a['previous'] = self::exceptionToArray($e->getPrevious());
}
return $a;
}
示例4: _formatException
/**
* Format exception
*
* @param Exception $e Exception
* @return array
*/
private function _formatException(Exception $e)
{
$result = ['message' => $e->getMessage(), 'code' => $e->getCode(), 'trace' => $e->getTrace()];
if ($previous = $e->getPrevious()) {
$result['previous'] = $this->_formatException($e->getPrevious());
}
return $result;
}
示例5: displayError
function displayError(Exception $error)
{
echo $error->getMessage() . "\n";
if ($error->getPrevious()) {
echo ' Underlying error: ';
displayError($error->getPrevious());
}
}
示例6: getPreviousExceptionInspector
/**
* Returns an Inspector for a previous Exception, if any.
*
* @return Inspector
*/
public function getPreviousExceptionInspector()
{
if ($this->previousExceptionInspector === null) {
$previousException = $this->exception->getPrevious();
if ($previousException) {
$this->previousExceptionInspector = new Inspector($previousException);
}
}
return $this->previousExceptionInspector;
}
示例7: findCodeDb
public static function findCodeDb(Exception $e)
{
if (isset($e->errorInfo)) {
return $e->errorInfo;
}
if ($e->getPrevious()) {
return self::findCodeDb($e->getPrevious());
} else {
return false;
}
}
示例8: buildError
/**
* @param \Exception $exception
*
* @return array
*/
protected function buildError(\Exception $exception)
{
$result = ['code' => $exception->getCode(), 'message' => $exception->getMessage(), 'previous' => null, 'data' => null];
if ($exception->getPrevious() !== null) {
$result['previous'] = $this->buildError($exception->getPrevious());
}
if ($exception instanceof ExceptionInterface) {
$result['data'] = $exception->getMetaData();
}
return $result;
}
示例9: serializeException
/**
* @param \Exception $exception
* @return string
*/
private static function serializeException(\Exception $exception)
{
$appendix = '';
$info = array_merge($exception->getMessage() ? array(self::serialize($exception->getMessage())) : array(), $exception->getCode() ? array(self::serialize($exception->getCode())) : array());
if ($info) {
$appendix = '(' . implode(', ', $info) . ')';
}
if ($exception->getPrevious()) {
$appendix .= ' <- ' . self::serializeException($exception->getPrevious());
}
return self::serializeObject($exception, $appendix);
}
示例10: __construct
/**
* Create Serializable exception from real exception
* @param \Exception $exception
*/
public function __construct(\Exception $exception)
{
$this->message = $exception->getMessage();
$this->traceString = $exception->getTraceAsString();
$this->code = $exception->getCode();
$this->file = $exception->getFile();
$this->line = $exception->getLine();
if ($exception->getPrevious() instanceof \Exception) {
$this->previous = new SerializableException($exception->getPrevious());
}
$this->trace = $exception->getTrace();
$this->cleanupTrace();
}
示例11: handle
/**
* {@inheritdoc}
*/
public function handle(\Exception $exception)
{
if (null !== ($preEx = $exception->getPrevious())) {
throw $preEx;
}
throw $exception;
}
示例12: 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";
}
}
}
}
}
示例13: handleException
/**
* Handles a thrown exception. Will also log extra information if the exception happens to by a MySql deadlock.
*
* @param \Exception $exception The exception captured.
*
* @return null
*/
protected function handleException($exception)
{
// Log MySQL deadlocks
if ($exception instanceof \CDbException && strpos($exception->getMessage(), 'Deadlock') !== false) {
$data = craft()->db->createCommand('SHOW ENGINE INNODB STATUS')->query();
$info = $data->read();
$info = serialize($info);
Craft::log('Deadlock error, innodb status: ' . $info, LogLevel::Error, 'system.db.CDbCommand');
}
// If this is a Twig Runtime exception, use the previous one instead
if ($exception instanceof \Twig_Error_Runtime) {
if ($previousException = $exception->getPrevious()) {
$exception = $previousException;
}
}
// Special handling for Twig syntax errors
if ($exception instanceof \Twig_Error) {
$this->handleTwigError($exception);
} else {
if ($exception instanceof DbConnectException) {
$this->handleDbConnectionError($exception);
} else {
parent::handleException($exception);
}
}
}
示例14: display
/**
* Outputs the error popup, or a plain message, depending on the response content type.
*
* @param \Exception|\Error $exception Note: can't be type hinted, for PHP7 compat.
* @param ResponseInterface|null $response If null, it outputs directly to the client. Otherwise, it assumes the
* object is a new blank response.
* @return ResponseInterface|null
*/
static function display($exception, ResponseInterface $response = null)
{
// For HTML pages, output the error popup
if (strpos(get($_SERVER, 'HTTP_ACCEPT'), 'text/html') !== false) {
ob_start();
ErrorConsoleRenderer::renderStyles();
$stackTrace = self::getStackTrace($exception->getPrevious() ?: $exception);
ErrorConsoleRenderer::renderPopup($exception, self::$appName, $stackTrace);
$popup = ob_get_clean();
// PSR-7 output
if ($response) {
$response->getBody()->write($popup);
return $response->withStatus(500);
}
// Direct output
echo $popup;
} else {
// PSR-7 output
if ($response) {
$response->getBody()->write($exception->getMessage());
if (self::$devEnv) {
$response->getBody()->write("\n\nStack trace:\n" . $exception->getTraceAsString());
}
return $response->withoutHeader('Content-Type')->withHeader('Content-Type', 'text-plain')->withStatus(500);
}
// Direct output
header("Content-Type: text/plain");
http_response_code(500);
echo $exception->getMessage();
if (self::$devEnv) {
echo "\n\nStack trace:\n" . $exception->getTraceAsString();
}
}
return null;
}
示例15: handle
public static function handle(\Exception $ex)
{
if ($ex->getPrevious() instanceof ConsoleException) {
Console::error($ex->getMessage());
return;
}
$handles = Settings::load('exception');
if (isset($handles) && !empty($handles)) {
foreach ($handles as $key => $value) {
if (self::recursive($ex, $key)) {
if (is_callable($value)) {
call_user_func($value, $ex);
return;
} else {
/** @var ExceptionHandle $handle */
$handle = DI::get($value);
if (isset($handle)) {
$handle->handle();
return;
}
}
}
}
}
throw $ex;
}