本文整理汇总了PHP中RuntimeException::getMessage方法的典型用法代码示例。如果您正苦于以下问题:PHP RuntimeException::getMessage方法的具体用法?PHP RuntimeException::getMessage怎么用?PHP RuntimeException::getMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RuntimeException
的用法示例。
在下文中一共展示了RuntimeException::getMessage方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: logError
/**
* @param \Zend\Mvc\MvcEvent $oEvent
* @return \BoilerAppLogger\Logger\MvcLogger
*/
public function logError(\Zend\Mvc\MvcEvent $oEvent)
{
//Create log error
$oLogError = new \BoilerAppLogger\Entity\LogErrorEntity();
if (!($oException = $oEvent->getParam('exception')) instanceof \Exception) {
if (!($oResponse = $oEvent->getResponse()) instanceof \Zend\Http\Response) {
throw new \LogicException(sprintf('Response expects an instance of \\Zend\\Http\\Response, "%s" given', is_object($oResponse) ? get_class($oResponse) : gettype($oResponse)));
}
$oException = new \RuntimeException($oEvent->getError(), $oResponse->getStatusCode());
} else {
$oLogError->setLogErrorFile($oException->getFile())->setLogErrorLine($oException->getLine());
}
$this->getLogErrorRepository()->create($oLogError->setLogErrorMessage($oException->getMessage())->setLogErrorCode($oException->getCode())->setLogErrorTrace($oException->getTraceAsString())->setLogErrorLog($this->getCurrentLog()));
return $this;
}
示例2: testCreateWithExceptionWithPrevious
/**
* Log events also take an exception as message argument (here with previous exception)
*/
public function testCreateWithExceptionWithPrevious()
{
$logEvent = LogEvent::create(ILogger::LEVEL_ERROR, $this->invargEx, array(), 'PHPUnit');
$logEventData = $logEvent->getArrayCopy();
$this->assertNotEmpty($logEventData);
$this->assertInternalType('array', $logEventData);
$this->assertArrayHasKey('msg', $logEventData);
$this->assertArrayHasKey('exception', $logEventData);
$this->assertEquals($this->invargEx->getMessage(), $logEventData['msg']);
$this->assertNotEmpty($logEventData['exception']);
$this->assertInternalType('array', $logEventData['exception']);
$exceptionArray = $logEventData['exception'];
$this->assertArrayHasKey('file', $exceptionArray);
$this->assertArrayHasKey('message', $exceptionArray);
$this->assertArrayHasKey('code', $exceptionArray);
$this->assertArrayHasKey('line', $exceptionArray);
$this->assertArrayHasKey('trace', $exceptionArray);
$this->assertArrayHasKey('previous', $exceptionArray);
$this->assertEquals(__FILE__, $exceptionArray['file']);
$this->assertEquals($this->invargEx->getMessage(), $exceptionArray['message']);
$this->assertEquals($this->invargEx->getCode(), $exceptionArray['code']);
$this->assertEquals($this->invargEx->getLine(), $exceptionArray['line']);
$this->assertNotEmpty($exceptionArray['trace']);
$previousArray = $exceptionArray['previous'];
$this->assertArrayHasKey('file', $previousArray);
$this->assertArrayHasKey('message', $previousArray);
$this->assertArrayHasKey('code', $previousArray);
$this->assertArrayHasKey('line', $previousArray);
$this->assertArrayHasKey('trace', $previousArray);
$this->assertArrayNotHasKey('previous', $previousArray);
$this->assertEquals(__FILE__, $previousArray['file']);
$this->assertEquals($this->runtimeEx->getMessage(), $previousArray['message']);
$this->assertEquals($this->runtimeEx->getCode(), $previousArray['code']);
$this->assertEquals($this->runtimeEx->getLine(), $previousArray['line']);
$this->assertNotEmpty($previousArray['trace']);
}
示例3: writeFailureLine
protected function writeFailureLine(OutputInterface $out, \RuntimeException $e)
{
$out->write('[ <error>FAIL</error> ] ');
$out->writeln($e->getMessage());
}
示例4: symlinkRetry
/**
* Wrapper to handle possible retry.
*
* @param $target
* @param $source
* @param $force
* @param $backup
* @param \RuntimeException $e
*/
protected function symlinkRetry($target, $source, $force, $backup, $relativeSource, \RuntimeException $e)
{
if ($force) {
if ($backup) {
$this->backup($target);
$this->output->writeln(sprintf('<comment>Created backup of %s.</comment>', $target));
}
$this->removeRecursive($target);
$this->output->writeln(sprintf('<comment>Removed %s.</comment>', $target));
// Retry.
$this->symlink($target, $source, FALSE, FALSE, $relativeSource);
} else {
$this->output->writeln('<error>' . $e->getMessage() . '</error>');
}
}
示例5: testDefFormatWithPreviousException
public function testDefFormatWithPreviousException()
{
$formatter = new JsonFormatter();
$exception = new \RuntimeException('Foo', 0, new \LogicException('Wut?'));
$message = $formatter->format(array('level_name' => 'CRITICAL', 'channel' => 'core', 'context' => array('exception' => $exception), 'datetime' => new \DateTime(), 'extra' => array(), 'message' => 'foobar'));
if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
$pathPrevious = substr(json_encode($exception->getPrevious()->getFile(), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), 1, -1);
$pathException = substr(json_encode($exception->getFile(), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), 1, -1);
} else {
$pathPrevious = substr(json_encode($exception->getPrevious()->getFile()), 1, -1);
$pathException = substr(json_encode($exception->getFile()), 1, -1);
}
$this->assertEquals('{"level_name":"CRITICAL","channel":"core","context":{"exception":{"class":"RuntimeException","message":"' . $exception->getMessage() . '","code":' . $exception->getCode() . ',"file":"' . $pathException . ':' . $exception->getLine() . '","previous":{"class":"LogicException","message":"' . $exception->getPrevious()->getMessage() . '","code":' . $exception->getPrevious()->getCode() . ',"file":"' . $pathPrevious . ':' . $exception->getPrevious()->getLine() . '"}}},"datetime":' . json_encode(new \DateTime()) . ',"extra":[],"message":"foobar"}' . "\n", $message);
}
示例6: extractMessage
/**
* Extract an error message from an exception thrown by Elastica.
* @param RuntimeException $exception exception from which to extract a message
* @return string message from the exception
*/
public static function extractMessage($exception)
{
if (!$exception instanceof ResponseException) {
return $exception->getMessage();
}
if ($exception instanceof PartialShardFailureException) {
$shardStats = $exception->getResponse()->getShardsStatistics();
$message = array();
foreach ($shardStats['failures'] as $failure) {
$message[] = $failure['reason'];
}
return 'Partial failure: ' . implode(',', $message);
}
return $exception->getElasticsearchException()->getMessage();
}
开发者ID:jamesmontalvo3,项目名称:mediawiki-extensions-CirrusSearch,代码行数:20,代码来源:ElasticsearchIntermediary.php
示例7: bin
/**
* `psysh` command line executable.
*
* @return Closure
*/
function bin()
{
return function () {
$usageException = null;
$input = new ArgvInput();
try {
$input->bind(new InputDefinition(array(new InputOption('help', 'h', InputOption::VALUE_NONE), new InputOption('config', 'c', InputOption::VALUE_REQUIRED), new InputOption('version', 'v', InputOption::VALUE_NONE), new InputOption('cwd', null, InputOption::VALUE_REQUIRED), new InputOption('color', null, InputOption::VALUE_NONE), new InputOption('no-color', null, InputOption::VALUE_NONE), new InputArgument('include', InputArgument::IS_ARRAY))));
} catch (\RuntimeException $e) {
$usageException = $e;
}
$config = array();
// Handle --config
if ($configFile = $input->getOption('config')) {
$config['configFile'] = $configFile;
}
// Handle --color and --no-color
if ($input->getOption('color') && $input->getOption('no-color')) {
$usageException = new \RuntimeException('Using both "--color" and "--no-color" options is invalid.');
} elseif ($input->getOption('color')) {
$config['colorMode'] = Configuration::COLOR_MODE_FORCED;
} elseif ($input->getOption('no-color')) {
$config['colorMode'] = Configuration::COLOR_MODE_DISABLED;
}
$shell = new Shell(new Configuration($config));
// Handle --help
if ($usageException !== null || $input->getOption('help')) {
if ($usageException !== null) {
echo $usageException->getMessage() . PHP_EOL . PHP_EOL;
}
$version = $shell->getVersion();
$name = basename(reset($_SERVER['argv']));
echo <<<EOL
{$version}
Usage:
{$name} [--version] [--help] [files...]
Options:
--help -h Display this help message.
--config -c Use an alternate PsySH config file location.
--cwd Use an alternate working directory.
--version -v Display the PsySH version.
--color Force colors in output.
--no-color Disable colors in output.
EOL;
exit($usageException === null ? 0 : 1);
}
// Handle --version
if ($input->getOption('version')) {
echo $shell->getVersion() . PHP_EOL;
exit(0);
}
// Pass additional arguments to Shell as 'includes'
$shell->setIncludes($input->getArgument('include'));
try {
// And go!
$shell->run();
} catch (Exception $e) {
echo $e->getMessage() . PHP_EOL;
// TODO: this triggers the "exited unexpectedly" logic in the
// ForkingLoop, so we can't exit(1) after starting the shell...
// fix this :)
// exit(1);
}
};
}
示例8: handleProcessorException
/**
* Handle the given exception, which was raised by the given processor.
*
* @param \Sitegear\Form\Processor\FormProcessorInterface $processor
* @param \RuntimeException $exception
*
* @return boolean
*
* @throws \RuntimeException
*/
protected function handleProcessorException(FormProcessorInterface $processor, \RuntimeException $exception)
{
$result = true;
switch ($processor->getExceptionAction()) {
case FormProcessorInterface::EXCEPTION_ACTION_MESSAGE:
$this->getEngine()->pageMessages()->add($exception->getMessage(), 'error');
$result = false;
break;
case FormProcessorInterface::EXCEPTION_ACTION_RETHROW:
throw $exception;
break;
case FormProcessorInterface::EXCEPTION_ACTION_FAIL:
$result = false;
break;
case FormProcessorInterface::EXCEPTION_ACTION_IGNORE:
break;
}
return $result;
}
示例9: getLocaleMessage
public function getLocaleMessage($locale = 'ja')
{
$message = KintoneMessageFactory::getInstance()->get(parent::getMessage(), $locale);
return strlen($message) ? $message : "Unknown error";
}
示例10: _actionException
/**
* Callback to handle both JError and Exception
*
* @param KCommandContext $context Command chain context
* caller => KObject, data => mixed
*
* @return KException
*/
protected function _actionException($context)
{
$exception = $context->data;
//if JException then conver it to KException
if ($exception instanceof JException) {
$exception = new RuntimeException($exception->getMessage(), $exception->getCode());
}
//if cli just print the error and exit
if (PHP_SAPI == 'cli') {
print "\n";
print $exception . "\n";
print debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
exit(0);
}
$code = $exception->getCode();
//check if the error is code is valid
if ($code < 400 || $code >= 600) {
$code = KHttpResponse::INTERNAL_SERVER_ERROR;
}
$context->response->status = $code;
$config = array('response' => $context->response, 'request' => $context->request, 'theme' => $this->_application->getTemplate());
//if ajax or the format is not html
//then return the exception in json format
if ($context->request->isAjax() || $context->request->getFormat() != 'html') {
$context->request->setFormat('json');
}
$this->getService('com://site/application.controller.exception', $config)->layout('error')->render($exception);
$this->send($context);
}
示例11: produce
/**
* Publishes a message to the backend.
*
* @param Message $message
* @return void
* @throws \RuntimeException If publishing fails
*/
public function produce(Message $message)
{
$type = $message->getType();
$body = array('ticket' => $message->getTicket());
try {
$this->logger->debug(sprintf('Publish message for job %s to sonata backend', $message->getTicket()), ['type' => $type, 'body' => $body]);
$queue = $this->registry->get($message->getType())->getQueue();
$this->backendProvider->getBackend($queue)->createAndPublish($type, $body);
} catch (\Exception $e) {
$this->logger->error(sprintf('Failed to publish message (Error: %s)', $e->getMessage()), ['exception' => $e]);
if (!$e instanceof \RuntimeException) {
$e = new \RuntimeException($e->getMessage(), $e->getCode(), $e);
}
throw $e;
}
}
示例12: testConstruct
public function testConstruct()
{
$exception = new RuntimeException('Oops');
$this->assertSame('Oops', $exception->getMessage());
}