当前位置: 首页>>代码示例>>PHP>>正文


PHP Exception::getMessage方法代码示例

本文整理汇总了PHP中Exception::getMessage方法的典型用法代码示例。如果您正苦于以下问题:PHP Exception::getMessage方法的具体用法?PHP Exception::getMessage怎么用?PHP Exception::getMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Exception的用法示例。


在下文中一共展示了Exception::getMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 /**
  * @param string     $resource       The resource that could not be imported
  * @param string     $sourceResource The original resource importing the new resource
  * @param int        $code           The error code
  * @param \Exception $previous       A previous exception
  */
 public function __construct($resource, $sourceResource = null, $code = null, $previous = null)
 {
     $message = '';
     if ($previous) {
         // Include the previous exception, to help the user see what might be the underlying cause
         // Trim the trailing period of the previous message. We only want 1 period remove so no rtrim...
         if ('.' === substr($previous->getMessage(), -1)) {
             $trimmedMessage = substr($previous->getMessage(), 0, -1);
             $message .= sprintf('%s', $trimmedMessage) . ' in ';
         } else {
             $message .= sprintf('%s', $previous->getMessage()) . ' in ';
         }
         $message .= $resource . ' ';
         // show tweaked trace to complete the human readable sentence
         if (null === $sourceResource) {
             $message .= sprintf('(which is loaded in resource "%s")', $this->varToString($resource));
         } else {
             $message .= sprintf('(which is being imported from "%s")', $this->varToString($sourceResource));
         }
         $message .= '.';
         // if there's no previous message, present it the default way
     } elseif (null === $sourceResource) {
         $message .= sprintf('Cannot load resource "%s".', $this->varToString($resource));
     } else {
         $message .= sprintf('Cannot import resource "%s" from "%s".', $this->varToString($resource), $this->varToString($sourceResource));
     }
     // Is the resource located inside a bundle?
     if ('@' === $resource[0]) {
         $parts = explode(DIRECTORY_SEPARATOR, $resource);
         $bundle = substr($parts[0], 1);
         $message .= ' ' . sprintf('Make sure the "%s" bundle is correctly registered and loaded in the application kernel class.', $bundle);
     }
     parent::__construct($message, $code, $previous);
 }
开发者ID:tahermarkos,项目名称:Transport,代码行数:40,代码来源:FileLoaderLoadException.php

示例2: run

 public function run()
 {
     if (Yii::$app->response->format == Response::FORMAT_HTML) {
         if ($this->debug || null === $this->exceptionView) {
             $file = $this->errorHandler->exceptionView;
             $this->response->data = $this->errorHandler->renderFile($file, ['exception' => $this->exception]);
             return $this->response;
         } else {
             return $this->controller->render($this->exceptionView, ['exception' => $this->exception]);
         }
     }
     if ($this->exception instanceof HttpException) {
         $code = $this->exception->statusCode;
     } elseif ($this->exception instanceof ResultsException || $this->exception instanceof UserException) {
         $code = $this->exception->getCode();
     } else {
         $code = 500;
     }
     if ($this->exception instanceof ResultsException) {
         $isSuccess = $this->exception->isSuccess;
     } else {
         $isSuccess = false;
     }
     $data = $this->exception instanceof ResultsException ? $this->exception->data : null;
     if ($this->debug) {
         $debugBacktrace = $this->convertExceptionToArray($this->exception);
     } else {
         $debugBacktrace = null;
     }
     return $this->controller->formatResults($code, $data, $isSuccess, $debugBacktrace, $this->exception->getMessage());
 }
开发者ID:hughcube,项目名称:yii2-web,代码行数:31,代码来源:ErrorAction.php

示例3: handler_exception

function handler_exception(Exception $e)
{
    if (APPLICATION_ENV == 'testing') {
        print $e->getMessage() . PHP_EOL;
        return;
    }
    error_log($e->getMessage());
    if (defined('BB_MODE_API')) {
        $code = $e->getCode() ? $e->getCode() : 9998;
        $result = array('result' => NULL, 'error' => array('message' => $e->getMessage(), 'code' => $code));
        print json_encode($result);
        return false;
    }
    $page = "<!DOCTYPE html>\n    <html lang=en>\n    <meta charset=utf-8>\n    <title>Error</title>\n    <style>\n    *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;min-height:180px;padding:30px 0 15px}* > body{padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0} em{font-weight:bold}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}pre{ width: 100%; overflow:auto; }\n    </style>\n    <a href=//www.boxbilling.com/ target='_blank'><img src='https://sites.google.com/site/boxbilling/_/rsrc/1308483006796/home/logo_boxbilling.png' alt='BoxBilling' style='height:60px'></a>\n    ";
    $page = str_replace(PHP_EOL, "", $page);
    print $page;
    if ($e->getCode()) {
        print sprintf('<p>Code: <em>%s</em></p>', $e->getCode());
    }
    print sprintf('<p>%s</p>', $e->getMessage());
    print sprintf('<p><a href="http://www.boxbilling.com/docs/search.html?q=%s" target="_blank">Look for detailed error explanation</a></p>', urlencode($e->getMessage()));
    if (defined('BB_DEBUG') && BB_DEBUG) {
        print sprintf('<em>%s</em>', 'Set BB_DEBUG to FALSE, to hide the message below');
        print sprintf('<p>Class: "%s"</p>', get_class($e));
        print sprintf('<p>File: "%s"</p>', $e->getFile());
        print sprintf('<p>Line: "%s"</p>', $e->getLine());
        print sprintf('Trace: <pre>%s</pre>', $e->getTraceAsString());
    }
}
开发者ID:nucther,项目名称:boxbilling,代码行数:29,代码来源:bb-load.php

示例4: exceptionHandler

 protected function exceptionHandler(\Exception $e)
 {
     $response = new Response();
     $code = $e instanceof IHttpExpection ? $e->getCode() : Response::CODE_INTERNAL_SERVER_ERROR;
     $response->setStatusCode($code, $e->getMessage())->setBody($e->getMessage());
     return $response;
 }
开发者ID:itmo-it-group-305,项目名称:sergey.poliakov-blog,代码行数:7,代码来源:Application.php

示例5: getErrorDetails

 protected function getErrorDetails(\Exception $exception, $code)
 {
     if (isset($this->exceptionMessages[$code])) {
         $error = $this->exceptionMessages[$code];
     } else {
         $error = $exception->getMessage();
     }
     if ($this->debug) {
         $message = $exception->getMessage();
         if (empty($message)) {
             $message = $error;
         }
         $class = get_class($exception);
         $file = $exception->getFile();
         $line = $exception->getLine();
         $trace = $exception->getTrace();
     } else {
         $message = $error;
         $class = 'Exception';
         $file = '';
         $line = '';
         $trace = array();
     }
     $result = array('error' => $error, 'message' => $message, 'code' => $code, 'class' => $class, 'file' => $file, 'line' => $line, 'trace' => $trace);
     return $result;
 }
开发者ID:lastzero,项目名称:symlex-core,代码行数:26,代码来源:ErrorRouter.php

示例6: action_show

 public function action_show()
 {
     $status = $this->error instanceof HttpException ? $this->error->getStatus() : '500 Internal Server Error';
     $data = $this->error instanceof HttpException ? $this->error->getData() : [];
     $this->response->add_header('HTTP/1.1 ' . $status);
     $displayErrors = $this->pixie->getParameter('parameters.display_errors', false);
     $showErrors = false;
     if ($this->error instanceof HttpException) {
         $message = $this->error->getMessage();
         if ($this->error->getCode() >= 400 || $this->error->getCode() < 100) {
             $showErrors = $displayErrors;
         }
     } else {
         if ($this->error instanceof SQLException) {
             if ($this->error->isVulnerable() && !$this->error->isBlind()) {
                 $showErrors = true;
                 $message = $this->error->getMessage();
             } else {
                 $message = "Error";
             }
         } else {
             $message = $this->error->getMessage();
             $showErrors = $displayErrors;
         }
     }
     $this->response->body = array_merge(['message' => $message, 'code' => $this->error->getCode(), 'trace' => $showErrors ? $this->error->getTraceAsString() : ""], $data);
 }
开发者ID:guitarooman14,项目名称:hackazon,代码行数:27,代码来源:ErrorController.php

示例7: sendExceptionByMail

 public static function sendExceptionByMail(Exception $e, $from, $to)
 {
     // generate mail datas
     $subject = '[' . MAIN_URL . ':' . CONFIG_ENV . '] Exception Report: ' . wordlimit_bychar($e->getMessage(), 50);
     $body = $e->getMessage() . ' in ' . $e->getFile() . ' at line ' . $e->getLine();
     // sned mail throw Zend_Mail
     $mail = new Zend_Mail();
     $mail->setSubject($subject)->setFrom($from)->setBodyText($body);
     $emails = explode(' ', $to);
     foreach ($emails as $email) {
         $mail->addTo($email);
     }
     $att = $mail->createAttachment(var_export($_GET, true), Zend_Mime::TYPE_TEXT);
     $att->filename = 'GET.txt';
     $att = $mail->createAttachment(var_export($_POST, true), Zend_Mime::TYPE_TEXT);
     $att->filename = 'POST.txt';
     // send session dump only if exists
     if (session_id() != null) {
         $att = $mail->createAttachment(var_export($_SESSION, true), Zend_Mime::TYPE_TEXT);
         $att->filename = 'SESSION.txt';
     }
     $att = $mail->createAttachment(var_export($_SERVER, true), Zend_Mime::TYPE_TEXT);
     $att->filename = 'SERVER.txt';
     $att = $mail->createAttachment($e->getTraceAsString(), Zend_Mime::TYPE_TEXT);
     $att->filename = 'backtraceExeption.txt';
     $mail->send();
 }
开发者ID:hartum,项目名称:basezf,代码行数:27,代码来源:Handler.php

示例8: render

 /**
  * Render an exception into an HTTP response.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Exception $e
  * @return \Illuminate\Http\Response
  */
 public function render($request, \Exception $e)
 {
     $this->response = app(Response::class);
     // Model not found
     if ($e instanceof ModelNotFoundException) {
         return $this->response->errorNotFound(['title' => 'No query results', 'code' => Error::CODE_RESOURCE_NOT_FOUND]);
     }
     // Wrongs argument
     if ($e instanceof InvalidArgumentException) {
         return $this->response->errorWrongArgs([$e->getMessage()]);
     }
     // Validator
     if ($e instanceof ValidatorException) {
         return $this->response->errorWrongArgsValidator($e->errors());
     }
     if ($e instanceof AuthorizationException) {
         return $this->response->errorUnauthorized([$e->getMessage()]);
     }
     // Route not found
     if ($e instanceof NotFoundHttpException) {
         return $this->response->errorNotFound();
     }
     //  Method not allowed
     if ($e instanceof MethodNotAllowedHttpException) {
         return $this->response->errorMethodNotAllowed();
     }
     if ($e instanceof InvalidRequestException) {
         return $this->response->errorUnauthorized([$e->getMessage()]);
     }
     if ($e instanceof AccessDeniedException) {
         return $this->response->errorUnauthorized([$e->getMessage()]);
     }
     return parent::render($request, $e);
 }
开发者ID:ellipsesynergie,项目名称:backend-skeleton,代码行数:41,代码来源:Handler.php

示例9: echoExceptionWeb

 /**
  * Echoes an exception for the web.
  *
  * @param \Exception $exception The exception
  * @return void
  */
 protected function echoExceptionWeb(\Exception $exception)
 {
     if ($exception instanceof Exception) {
         $statusCode = 400;
         $json = ['status' => 'invalid_request', 'reason' => $exception->getMessage()];
     } elseif ($exception instanceof \TYPO3\Flow\Security\Exception) {
         $statusCode = 403;
         $json = ['status' => 'unauthorized', 'reason' => $exception->getMessage()];
     } else {
         $statusCode = 500;
         if ($exception instanceof FlowException) {
             $statusCode = $exception->getStatusCode();
         }
         $json = ['status' => 'error', 'reason' => $exception->getMessage(), 'errorClass' => get_class($exception)];
     }
     if ($exception->getPrevious() !== NULL) {
         $json['previous'] = $exception->getPrevious()->getMessage();
     }
     $json['stacktrace'] = explode("\n", $exception->getTraceAsString());
     $statusMessage = Response::getStatusMessageByCode($statusCode);
     if (!headers_sent()) {
         header(sprintf('HTTP/1.1 %s %s', $statusCode, $statusMessage));
         header('Content-Type: application/json');
     }
     print json_encode($json);
 }
开发者ID:mmolle-nelo,项目名称:flow-resttools,代码行数:32,代码来源:DevelopmentRestExceptionHandler.php

示例10: createFailJsonResponse

 /**
  * @param \Exception $exception
  * @param array      $data
  * 
  * @return JsonResponse
  */
 protected function createFailJsonResponse(\Exception $exception, $data)
 {
     if (!$this->isProdEnv()) {
         return new JsonResponse(['success' => 'nok', 'error' => $exception->getMessage(), 'trace' => $exception->getTrace(), 'data' => $data]);
     }
     return new JsonResponse(['success' => 'nok', 'error' => $exception->getMessage()]);
 }
开发者ID:rsmakota,项目名称:ortofit_backoffice,代码行数:13,代码来源:BaseController.php

示例11: showException

 /**
  * Show exception screen
  *
  * @param \Exception $exception
  */
 public function showException(\Exception $exception)
 {
     @ob_end_clean();
     $msg = sprintf("%s\nFile: %s\nLine: %d\nTrace:\n%s", $exception->getMessage(), $exception->getFile(), $exception->getLine(), $exception->getTraceAsString());
     \Kalibri::logger()->add(Logger::L_EXCEPTION, $msg);
     $viewName = \Kalibri::config()->get('error.view.exception');
     if ($viewName) {
         $view = new \Kalibri\View($viewName);
         $view->ex = $exception;
         $str = '';
         $file = \fopen($exception->getFile(), 'r');
         for ($i = 0; $i < $exception->getLine() - 16; $i++) {
             \fgets($file);
         }
         for ($i = 0; $i < 20; $i++) {
             $str .= \fgets($file);
         }
         $view->code = Highlight::php($str, true, 1, $exception->getLine());
         if ($view->isExists()) {
             $view->render();
         } else {
             // Fallback to show any message in case if exception view not found or not set
             echo "<h1>Exception</h1><p>{$exception->getMessage()}</p>";
         }
     }
     exit;
 }
开发者ID:tenebras,项目名称:kalibri,代码行数:32,代码来源:Error.php

示例12: exception

 public static function exception(\Exception $e)
 {
     // echo get_class($e).'<br />';
     if ($e->getCode() !== 0 && !(error_reporting() & $e->getCode())) {
         // This error code is not included in error_reporting
         return;
     }
     switch ($e->getCode()) {
         case E_USER_ERROR:
             echo '<b>USER ERROR</b> ' . $e->getCode() . ' ' . $e->getMessage() . '<br />\\n';
             echo '  Fatal error on line ' . $e->getLine() . ' in file ' . $e->getFile();
             echo ', PHP ' . PHP_VERSION . ' (' . PHP_OS . ')<br />\\n';
             echo 'Aborting...<br />\\n';
             exit(1);
             break;
         case E_USER_WARNING:
             echo '<b>WARNING</b> ' . $e->getCode() . ' ' . $e->getMessage() . '<br />\\n';
             break;
         case E_USER_NOTICE:
             echo '<b>NOTICE</b> ' . $e->getCode() . ' ' . $e->getMessage() . '<br />\\n';
             break;
         default:
             self::printError($e);
             break;
     }
     /* Don't execute PHP internal error handler */
     return true;
 }
开发者ID:audacus,项目名称:constructive-damage,代码行数:28,代码来源:ErrorController.php

示例13: onKernelResponse

 public function onKernelResponse(FilterResponseEvent $event)
 {
     $debug = $this->container->getParameter('rest.config')['debug'];
     $arr = $event->getRequest()->headers->get("accept");
     if (!is_array($arr)) {
         $arr = array($arr);
     }
     if (is_array($arr) && (in_array("text/html", $arr) || in_array("*/*", $arr))) {
         return;
     }
     $response = $event->getResponse();
     if (in_array($response->headers->get("content-type"), $arr)) {
         return;
     }
     $error = $response->isServerError() || $event->getResponse()->isClientError();
     if ($error && self::$exception != null) {
         $result = array();
         $result["status"] = $response->getStatusCode();
         if (self::$exception != null) {
             $result["message"] = self::$exception->getMessage();
             if ($debug) {
                 $result["stacktrace"] = self::$exception->getTraceAsString();
             }
         } else {
             $result["message"] = "unknown";
             if ($debug) {
                 $result["stacktrace"] = "";
             }
         }
         $classParser = $this->container->get("rest.internal_class_parser");
         $content = $classParser->serializeObject($result, true);
         $response->setContent($content["result"]);
         $response->headers->add(array("content-type" => $content["type"]));
     }
 }
开发者ID:freefair,项目名称:rest-bundle,代码行数:35,代码来源:ResponseListener.php

示例14: handleException

 public function handleException(Exception $exception, $shutdown = false)
 {
     $this->_exception = $exception;
     $email = new CakeEmail('error');
     $prefix = Configure::read('ExceptionNotifier.prefix');
     $from = $email->from();
     if (empty($from)) {
         $email->from('exception.notifier@default.com', 'Exception Notifier');
     }
     $subject = $email->subject();
     if (empty($subject)) {
         $email->subject($prefix . '[' . date('Ymd H:i:s') . '][' . $this->_getSeverityAsString() . '][' . ExceptionText::getUrl() . '] ' . $exception->getMessage());
     }
     if ($this->useSmtp) {
         $email->transport('Smtp');
         $email->config($this->smtpParams);
     }
     $text = ExceptionText::getText($exception->getMessage(), $exception->getFile(), $exception->getLine());
     $email->send($text);
     // return Exception.handler
     if ($shutdown || !$this->_exception instanceof ErrorException) {
         $config = Configure::read('Exception');
         $handler = $config['handler'];
         if (is_string($handler)) {
             call_user_func($handler, $exception);
         } elseif (is_array($handler)) {
             call_user_func_array($handler, $exception);
         }
     }
 }
开发者ID:k1low,项目名称:exception,代码行数:30,代码来源:ExceptionNotifierComponent.php

示例15: 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);
     }
 }
开发者ID:KasaiDot,项目名称:FoolFrame,代码行数:40,代码来源:ExceptionHandler.php


注:本文中的Exception::getMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。