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


PHP Exception::getCode方法代码示例

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


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

示例1: 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

示例2: writeLogEntries

 /**
  * Writes exception to different logs
  *
  * @param \Exception|\Throwable $exception The exception(PHP 5.x) or throwable(PHP >= 7.0) object.
  * @param string $context The context where the exception was thrown, WEB or CLI
  * @return void
  * @see \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog(), \TYPO3\CMS\Core\Utility\GeneralUtility::devLog()
  * @TODO #72293 This will change to \Throwable only if we are >= PHP7.0 only
  */
 protected function writeLogEntries($exception, $context)
 {
     // Do not write any logs for this message to avoid filling up tables or files with illegal requests
     if ($exception->getCode() === 1396795884) {
         return;
     }
     $filePathAndName = $exception->getFile();
     $exceptionCodeNumber = $exception->getCode() > 0 ? '#' . $exception->getCode() . ': ' : '';
     $logTitle = 'Core: Exception handler (' . $context . ')';
     $logMessage = 'Uncaught TYPO3 Exception: ' . $exceptionCodeNumber . $exception->getMessage() . ' | ' . get_class($exception) . ' thrown in file ' . $filePathAndName . ' in line ' . $exception->getLine();
     if ($context === 'WEB') {
         $logMessage .= '. Requested URL: ' . GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL');
     }
     $backtrace = $exception->getTrace();
     // Write error message to the configured syslogs
     GeneralUtility::sysLog($logMessage, $logTitle, GeneralUtility::SYSLOG_SEVERITY_FATAL);
     // When database credentials are wrong, the exception is probably
     // caused by this. Therefor we cannot do any database operation,
     // otherwise this will lead into recurring exceptions.
     try {
         // Write error message to devlog
         // see: $TYPO3_CONF_VARS['SYS']['enable_exceptionDLOG']
         if (TYPO3_EXCEPTION_DLOG) {
             GeneralUtility::devLog($logMessage, $logTitle, 3, array('TYPO3_MODE' => TYPO3_MODE, 'backtrace' => $backtrace));
         }
         // Write error message to sys_log table
         $this->writeLog($logTitle . ': ' . $logMessage);
     } catch (\Exception $exception) {
     }
 }
开发者ID:sup7even,项目名称:TYPO3-schulung-Distribution,代码行数:39,代码来源:AbstractExceptionHandler.php

示例3: severity

 /**
  * Get a human-readable version of the exception error code.
  *
  * @return string
  */
 public function severity()
 {
     if (array_key_exists($this->exception->getCode(), $this->levels)) {
         return $this->levels[$this->exception->getCode()];
     }
     return $this->exception->getCode();
 }
开发者ID:hpaul,项目名称:Google-short,代码行数:12,代码来源:examiner.php

示例4: 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();
 }
开发者ID:krisanalfa,项目名称:docolight,代码行数:34,代码来源:RestFulController.php

示例5: exceptionHandler

/**
 * @param \Exception $e
 * @return bool
 */
function exceptionHandler(\Exception $e)
{
    echo '<h1>Error</h1><p>Sorry, the script died with a exception</p>';
    echo $e->getMessage() . ' in <br>' . $e->getFile() . ': <br>' . $e->getLine(), ' : <br>', __FUNCTION__, ' : <br>', $e->getTraceAsString();
    log::error($e->getMessage() . ' in ' . $e->getFile() . ':' . $e->getLine() . "<br>\n", "Code: " . $e->getCode(), $e->getTrace());
    mail(ADMIN_MAIL, '[GitReminder] System got locked', $e->getMessage() . ' in ' . $e->getFile() . ':' . $e->getLine() . "\n\n" . "Funktion -> " . __FUNCTION__ . $e->getTraceAsString() . "\n\n" . "Code: " . $e->getCode());
    @trigger_error('', E_USER_ERROR);
}
开发者ID:ADoebeling,项目名称:GitReminder,代码行数:12,代码来源:bootstrap.php

示例6: validationError

 public function validationError($field, $data, \Exception $e)
 {
     $fex = new ValidatorException(sprintf($this->standardMessage, $field, $e->getMessage(), $e->getCode()), $e->getCode(), $e);
     $fex->field = $field;
     $fex->data = $data;
     return $fex;
 }
开发者ID:pscheit,项目名称:psc-cms,代码行数:7,代码来源:ServiceErrorPackage.php

示例7: writeLogEntries

 /**
  * Writes exception to different logs
  *
  * @param Exception $exception The exception
  * @param string 	the context where the exception was thrown, WEB or CLI
  * @return void
  * @see t3lib_div::sysLog(), t3lib_div::devLog()
  */
 protected function writeLogEntries(Exception $exception, $context)
 {
     $filePathAndName = $exception->getFile();
     $exceptionCodeNumber = $exception->getCode() > 0 ? '#' . $exception->getCode() . ': ' : '';
     $logTitle = 'Core: Exception handler (' . $context . ')';
     $logMessage = 'Uncaught TYPO3 Exception: ' . $exceptionCodeNumber . $exception->getMessage() . ' | ' . get_class($exception) . ' thrown in file ' . $filePathAndName . ' in line ' . $exception->getLine();
     $backtrace = $exception->getTrace();
     // write error message to the configured syslogs
     t3lib_div::sysLog($logMessage, $logTitle, 4);
     // When database credentials are wrong, the exception is probably
     // caused by this. Therefor we cannot do any database operation,
     // otherwise this will lead into recurring exceptions.
     try {
         // In case an error occurs before a database connection exists, try
         // to connect to the DB to be able to write the devlog/sys_log entry
         if (isset($GLOBALS['TYPO3_DB']) && is_object($GLOBALS['TYPO3_DB']) && empty($GLOBALS['TYPO3_DB']->link)) {
             $GLOBALS['TYPO3_DB']->connectDB();
         }
         // write error message to devlog
         // see: $TYPO3_CONF_VARS['SYS']['enable_exceptionDLOG']
         if (TYPO3_EXCEPTION_DLOG) {
             t3lib_div::devLog($logMessage, $logTitle, 3, array('TYPO3_MODE' => TYPO3_MODE, 'backtrace' => $backtrace));
         }
         // write error message to sys_log table
         $this->writeLog($logTitle . ': ' . $logMessage);
     } catch (Exception $exception) {
         // Nothing happens here. It seems the database credentials are wrong
     }
 }
开发者ID:zsolt-molnar,项目名称:TYPO3-4.5-trunk,代码行数:37,代码来源:class.t3lib_error_abstractexceptionhandler.php

示例8: 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

示例9: 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);
     $this->response->body = array_merge(['message' => $this->error->getMessage(), 'code' => $this->error->getCode()], $data);
 }
开发者ID:nchervyakov,项目名称:evolve2,代码行数:7,代码来源:ErrorController.php

示例10: writeLogEntries

 /**
  * Writes exception to different logs
  *
  * @param Exception $exception The exception
  * @param string $context The context where the exception was thrown, WEB or CLI
  * @return void
  * @see t3lib_div::sysLog(), t3lib_div::devLog()
  */
 protected function writeLogEntries(\Exception $exception, $context)
 {
     $filePathAndName = $exception->getFile();
     $exceptionCodeNumber = $exception->getCode() > 0 ? '#' . $exception->getCode() . ': ' : '';
     $logTitle = 'Core: Exception handler (' . $context . ')';
     $logMessage = 'Uncaught TYPO3 Exception: ' . $exceptionCodeNumber . $exception->getMessage() . ' | ' . get_class($exception) . ' thrown in file ' . $filePathAndName . ' in line ' . $exception->getLine();
     if ($context === 'WEB') {
         $logMessage .= '. Requested URL: ' . \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL');
     }
     $backtrace = $exception->getTrace();
     // Write error message to the configured syslogs
     \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog($logMessage, $logTitle, \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_FATAL);
     // When database credentials are wrong, the exception is probably
     // caused by this. Therefor we cannot do any database operation,
     // otherwise this will lead into recurring exceptions.
     try {
         // In case an error occurs before a database connection exists, try
         // to connect to the DB to be able to write the devlog/sys_log entry
         if (isset($GLOBALS['TYPO3_DB']) && is_object($GLOBALS['TYPO3_DB']) && empty($GLOBALS['TYPO3_DB']->link)) {
             $GLOBALS['TYPO3_DB']->connectDB();
         }
         // Write error message to devlog
         // see: $TYPO3_CONF_VARS['SYS']['enable_exceptionDLOG']
         if (TYPO3_EXCEPTION_DLOG) {
             \TYPO3\CMS\Core\Utility\GeneralUtility::devLog($logMessage, $logTitle, 3, array('TYPO3_MODE' => TYPO3_MODE, 'backtrace' => $backtrace));
         }
         // Write error message to sys_log table
         $this->writeLog($logTitle . ': ' . $logMessage);
     } catch (\Exception $exception) {
     }
 }
开发者ID:nicksergio,项目名称:TYPO3v4-Core,代码行数:39,代码来源:AbstractExceptionHandler.php

示例11: 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

示例12: renderControllerException

 /**
  * Render an exception using ErrorController.
  *
  * @param \Exception $e
  *
  * @return \Illuminate\Http\Response
  */
 protected function renderControllerException(\Exception $e)
 {
     $code = 500;
     if ($e instanceof HttpResponseException) {
         $code = $e->getStatusCode();
     } else {
         if ($e->getCode() > 0) {
             $code = $e->getCode();
         }
     }
     try {
         /** @var ErrorController $controller */
         $controller = app()->make(ErrorController::class);
         if (method_exists($controller, 'error' . $code)) {
             $action = 'error' . $code;
         } else {
             $action = 'errorDefault';
         }
         $response = $controller->callAction($action, [$e]);
         if (!$response instanceof Response) {
             $response = new Response($response);
         }
         return $this->toIlluminateResponse($response, $e);
     } catch (\Exception $ex) {
         return $this->toIlluminateResponse($this->convertExceptionToResponse($ex), $ex);
     }
 }
开发者ID:KodiComponents,项目名称:module-core,代码行数:34,代码来源:Handler.php

示例13: handle

 /**
  * handle() hook.
  *
  * @param App $app
  * @param BaseException $e
  * @return void
  */
 public function handle(App $app, BaseException $e)
 {
     $reg = $app['reg'];
     /* @var Registry $reg */
     $tpl = $app['tpl'];
     /* @var Tpl $tpl */
     $router = $app['router'];
     /* @var Router $router */
     switch ($reg->get('app.mode')) {
         case 'web':
             $httpStatus = 500;
             $tplName = 'exceptions/common.twig';
             $reg->set('page.title', trans('error', array('code' => $e->getCode())));
             if ($e instanceof HttpException) {
                 $httpStatus = $e->getCode();
             }
             if ($e instanceof ForbiddenException) {
                 $tplName = 'exceptions/http-403.twig';
             }
             if ($e instanceof NotFoundException) {
                 $tplName = 'exceptions/http-404.twig';
             }
             if ($e instanceof MethodNotAllowedException) {
                 $tplName = 'exceptions/http-405.twig';
             }
             $content = $tpl->renderFile($tplName, array('header' => $reg->get('page.title'), 'message' => $e->getMessage(), 'exception' => $e));
             $response = $router->createResponse($content, $httpStatus);
             $response->send();
             break;
         case 'cli':
             break;
     }
 }
开发者ID:simsite,项目名称:project,代码行数:40,代码来源:Exception.php

示例14: uncaughtExceptionHandler

 public function uncaughtExceptionHandler(Exception $e)
 {
     if ($e->getCode() != 0) {
         $this->dieWithFaultResponse($e->getCode(), $e->getMessage());
     } else {
         $this->handleInternalError($e->getMessage(), $e->getFile(), $e->getLine());
     }
 }
开发者ID:klickverbot,项目名称:theBlackboard,代码行数:8,代码来源:FrontController.php

示例15: handleException

/**
 * Handle a exception in the console environment. Prints a message to stderr.
 *
 * @param Exception $exception The exception to handle
 * @return void
 */
	public function handleException(Exception $exception) {
		$stderr = self::getStderr();
		$stderr->write(__d('cake_console', "<error>Error:</error> %s\n%s",
			$exception->getMessage(),
			$exception->getTraceAsString()
		));
		$this->_stop($exception->getCode() ? $exception->getCode() : 1);
	}
开发者ID:hungnt88,项目名称:5stars-1,代码行数:14,代码来源:ConsoleErrorHandler.php


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