getName() public method

public getName ( ) : string
return string the user-friendly name of this exception
コード例 #1
0
ファイル: ErrorHandler.php プロジェクト: diandianxiyu/Yii2Api
 /**
  * Converts an exception into a simple string.
  * @param \Exception $exception the exception being converted
  * @return string the string representation of the exception.
  */
 public static function convertExceptionToString($exception)
 {
     if ($exception instanceof Exception && ($exception instanceof UserException || !YII_DEBUG)) {
         $message = "{$exception->getName()}: {$exception->getMessage()}";
     } elseif (YII_DEBUG) {
         if ($exception instanceof Exception) {
             $message = "Exception ({$exception->getName()})";
         } elseif ($exception instanceof ErrorException) {
             $message = "{$exception->getName()}";
         } else {
             $message = 'Exception';
         }
         $message .= " '" . get_class($exception) . "' with message '{$exception->getMessage()}' \n\nin " . $exception->getFile() . ':' . $exception->getLine() . "\n\n" . "Stack trace:\n" . $exception->getTraceAsString();
     } else {
         $message = 'Error: ' . $exception->getMessage();
     }
     return $message;
 }
コード例 #2
0
 /**
  * Renders an exception without using rich format.
  * @param \Exception $exception the exception to be rendered.
  * @return string the rendering result
  */
 public function renderException($exception)
 {
     if ($exception instanceof Exception && ($exception instanceof UserException || !YII_DEBUG)) {
         $message = $exception->getName() . ': ' . $exception->getMessage();
         if (Yii::$app->controller instanceof \yii\console\Controller) {
             $message = Yii::$app->controller->ansiFormat($message, Console::FG_RED);
         }
     } else {
         $message = YII_DEBUG ? (string) $exception : 'Error: ' . $exception->getMessage();
     }
     if (PHP_SAPI === 'cli') {
         return $message . "\n";
     } else {
         return '<pre>' . htmlspecialchars($message, ENT_QUOTES, $this->charset) . '</pre>';
     }
 }