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


PHP Throwable::getCode方法代码示例

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


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

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

示例2: handleException

 /**
  * @param \Throwable $e
  */
 public function handleException(\Throwable $e)
 {
     $code = $e->getCode() >= 400 ? $e->getCode() : 500;
     $exceptionData = ['error' => ['code' => $e->getCode(), 'message' => $e->getMessage()]];
     http_response_code($code);
     echo json_encode($exceptionData, JSON_PRETTY_PRINT);
     exit(1);
 }
开发者ID:belanur,项目名称:docker-example,代码行数:11,代码来源:ErrorHandler.php

示例3: error

 /**
  * Return an error into an HTTP or JSON data array.
  *
  * @param string $title
  * @return array
  */
 public function error($title = null)
 {
     if ($title == null) {
         $title = $this->debug ? 'The application could not run because of the following error:' : 'A website error has occurred. Sorry for the temporary inconvenience.';
     }
     $type = $this->request->getHeader('Content-Type');
     $mesg = $this->exception->getMessage();
     $file = $this->exception->getFile();
     $line = $this->exception->getLine();
     $code = $this->exception->getCode();
     $statusCode = method_exists($this->exception, 'getStatusCode') ? $this->exception->getStatusCode() : null;
     // Check status code is null
     if ($statusCode == null) {
         $statusCode = $code >= 100 && $code <= 500 ? $code : 400;
     }
     $this->response->withStatus($statusCode);
     // Check logger exist
     if ($this->logger !== null) {
         // Send error to log
         $this->logger->addError($this->exception->getMessage());
     }
     $this->isJson = isset($type[0]) && $type[0] == 'application/json';
     // Check content-type is application/json
     if ($this->isJson) {
         // Define content-type to json
         $this->response->withHeader('Content-Type', 'application/json');
         $error = ['status' => 'error', 'status_code' => $statusCode, 'error' => $title, 'details' => []];
         // Check debug
         if ($this->debug) {
             $error['details'] = ['message' => $mesg, 'file' => $file, 'line' => $line, 'code' => $code];
         }
         return $error;
     }
     // Define content-type to html
     $this->response->withHeader('Content-Type', 'text/html');
     $message = sprintf('<span>%s</span>', htmlentities($mesg));
     $error = ['type' => get_class($this->exception), $error['status_code'] = $statusCode, 'message' => $message];
     // Check debug
     if ($this->debug) {
         $trace = $this->exception->getTraceAsString();
         $trace = sprintf('<pre>%s</pre>', htmlentities($trace));
         $error['file'] = $file;
         $error['line'] = $line;
         $error['code'] = $code;
         $error['trace'] = $trace;
     }
     $error['debug'] = $this->debug;
     $error['title'] = $title;
     return $error;
 }
开发者ID:aracaw,项目名称:wiring,代码行数:56,代码来源:ErrorHandler.php

示例4: 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()
  */
 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 === self::CONTEXT_WEB) {
         $logMessage .= '. Requested URL: ' . GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL');
     }
     // Write error message to the configured syslogs
     GeneralUtility::sysLog($logMessage, $logTitle, GeneralUtility::SYSLOG_SEVERITY_FATAL);
 }
开发者ID:helhum,项目名称:typo3-distribution,代码行数:24,代码来源:AbstractExceptionHandler.php

示例5: exceptionHandler

 /**
  * @param \Throwable $exception
  *
  * @return bool
  */
 public function exceptionHandler(\Throwable $exception)
 {
     if ($exception instanceof ResponseCode) {
         try {
             $out = $this->render($exception->getCode(), [], $exception->display());
         } catch (\Throwable $exception) {
             return $this->exceptionHandler($exception);
         }
         // debug on dev / display trace
         if (!(AbstractApp::env() != AbstractApp::PRODUCTION && ob_get_length() > 0)) {
             self::response()->addHeader('Content-Type', $this->getErrorContentType());
         }
         self::response()->setStatus($exception->getCode());
         self::response()->setBody($out);
         HttpApp::instance()->end();
     } else {
         Handler::log($exception);
         if (AbstractApp::env() != AbstractApp::PRODUCTION) {
             Handler::exceptionHandler($exception);
         } else {
             $throw = new ResponseCode($exception->getMessage(), 500, $exception);
             $this->exceptionHandler($throw);
         }
     }
     return true;
 }
开发者ID:cawaphp,项目名称:module-swagger-server,代码行数:31,代码来源:AbstractRenderer.php

示例6: render

 /**
  * Render the document
  *
  * @param   boolean  $cache   If true, cache the output
  * @param   array    $params  Associative array of attributes
  *
  * @return  string   The rendered data
  *
  * @since   11.1
  */
 public function render($cache = false, $params = array())
 {
     // If no error object is set return null
     if (!isset($this->_error)) {
         return;
     }
     // Set the status header
     $status = $this->_error->getCode();
     if ($status < 400 || $status > 599) {
         $status = 500;
     }
     JFactory::getApplication()->setHeader('status', $status . ' ' . str_replace("\n", ' ', $this->_error->getMessage()));
     $file = 'error.php';
     // Check template
     $directory = isset($params['directory']) ? $params['directory'] : 'templates';
     $template = isset($params['template']) ? JFilterInput::getInstance()->clean($params['template'], 'cmd') : 'system';
     if (!file_exists($directory . '/' . $template . '/' . $file)) {
         $template = 'system';
     }
     // Set variables
     $this->baseurl = JUri::base(true);
     $this->template = $template;
     $this->debug = isset($params['debug']) ? $params['debug'] : false;
     $this->error = $this->_error;
     // Load the language file for the template if able
     if (JFactory::$language) {
         $lang = JFactory::getLanguage();
         // 1.5 or core then 1.6
         $lang->load('tpl_' . $template, JPATH_BASE, null, false, true) || $lang->load('tpl_' . $template, $directory . '/' . $template, null, false, true);
     }
     // Load
     $data = $this->_loadTemplate($directory . '/' . $template, $file);
     parent::render();
     return $data;
 }
开发者ID:Rai-Ka,项目名称:joomla-cms,代码行数:45,代码来源:error.php

示例7: __construct

 /**
  * @inheritDoc
  */
 public function __construct(\Throwable $t)
 {
     $this->message = $t->getMessage();
     $this->code = $t->getCode();
     $this->file = $t->getFile();
     $this->line = $t->getLine();
 }
开发者ID:aurimasniekis,项目名称:thruster,代码行数:10,代码来源:WrappedThrowable.php

示例8: render

 /**
  * Render the error page based on an exception.
  *
  * @param   Exception|Throwable  $error  An Exception or Throwable (PHP 7+) object for which to render the error page.
  *
  * @return  void
  *
  * @since   3.0
  */
 public static function render($error)
 {
     $expectedClass = PHP_MAJOR_VERSION >= 7 ? 'Throwable' : 'Exception';
     $isException = $error instanceof $expectedClass;
     // In PHP 5, the $error object should be an instance of Exception; PHP 7 should be a Throwable implementation
     if ($isException) {
         try {
             // If site is offline and it's a 404 error, just go to index (to see offline message, instead of 404)
             if ($error->getCode() == '404' && JFactory::getConfig()->get('offline') == 1) {
                 JFactory::getApplication()->redirect('index.php');
             }
             $app = JFactory::getApplication();
             $document = JDocument::getInstance('error');
             if (!$document) {
                 // We're probably in an CLI environment
                 jexit($error->getMessage());
             }
             // Get the current template from the application
             $template = $app->getTemplate();
             // Push the error object into the document
             $document->setError($error);
             if (ob_get_contents()) {
                 ob_end_clean();
             }
             $document->setTitle(JText::_('Error') . ': ' . $error->getCode());
             $data = $document->render(false, array('template' => $template, 'directory' => JPATH_THEMES, 'debug' => JDEBUG));
             // Do not allow cache
             $app->allowCache(false);
             // If nothing was rendered, just use the message from the Exception
             if (empty($data)) {
                 $data = $error->getMessage();
             }
             $app->setBody($data);
             echo $app->toString();
             $app->close(0);
             // This return is needed to ensure the test suite does not trigger the non-Exception handling below
             return;
         } catch (Throwable $e) {
             // Pass the error down
         } catch (Exception $e) {
             // Pass the error down
         }
     }
     // This isn't an Exception, we can't handle it.
     if (!headers_sent()) {
         header('HTTP/1.1 500 Internal Server Error');
     }
     $message = 'Error displaying the error page';
     if ($isException) {
         $message .= ': ';
         if (isset($e)) {
             $message .= $e->getMessage() . ': ';
         }
         $message .= $error->getMessage();
     }
     echo $message;
     jexit(1);
 }
开发者ID:adjaika,项目名称:J3Base,代码行数:67,代码来源:page.php

示例9: handle_exception

 /**
  * @param \Exception|\Throwable $exception
  */
 public function handle_exception($exception)
 {
     if (getenv('APP_ENV') === 'dev') {
         list($code, $file, $line, $message, $previous, $trace, $trace_string) = [$exception->getCode(), $exception->getFile(), $exception->getLine(), $exception->getMessage(), $exception->getPrevious(), $exception->getTrace(), $exception->getTraceAsString()];
         $trace_info = "<b>file</b>: {$trace[0]['file']} <b>in line</b> ({$trace[0]['line']})";
         echo "<h2>COGS Runtime Exception: [::{$code}] {$message}</h2>";
         echo "<b>Trace:</b><br>";
         echo "<pre>{$trace_string}</pre>";
         echo "<b>Debug:</b><br>";
         dump(compact('code', 'file', 'line', 'message', 'previous', 'trace'));
     }
 }
开发者ID:anctemarry27,项目名称:cogs,代码行数:15,代码来源:ErrorHandlingServiceProvider.php

示例10: __construct

 public function __construct(\Throwable $e)
 {
     if ($e instanceof \ParseError) {
         $message = 'Parse error: ' . $e->getMessage();
         $severity = E_PARSE;
     } elseif ($e instanceof \TypeError) {
         $message = 'Type error: ' . $e->getMessage();
         $severity = E_RECOVERABLE_ERROR;
     } else {
         $message = $e->getMessage();
         $severity = E_ERROR;
     }
     \ErrorException::__construct($message, $e->getCode(), $severity, $e->getFile(), $e->getLine());
     $this->setTrace($e->getTrace());
 }
开发者ID:zanderbaldwin,项目名称:symfony,代码行数:15,代码来源:FatalThrowableError.php

示例11: doRender

 /**
  * Render the error page for the given object
  *
  * @param   \Throwable|\Exception  $error  The error object to be rendered
  *
  * @return  string
  *
  * @since   4.0
  */
 protected function doRender($error)
 {
     // Create our data object to be rendered
     $data = ['error' => true, 'code' => $error->getCode(), 'message' => $error->getMessage()];
     // Include the stack trace if in debug mode
     if (JDEBUG) {
         $data['trace'] = $error->getTraceAsString();
     }
     // Push the data object into the document
     $this->getDocument()->setBuffer(json_encode($data));
     if (ob_get_contents()) {
         ob_end_clean();
     }
     return $this->getDocument()->render();
 }
开发者ID:Rai-Ka,项目名称:joomla-cms,代码行数:24,代码来源:JsonRenderer.php

示例12: dispatchException

 /**
  * Send exception message to client
  * @param \Exception $exception
  */
 public function dispatchException(\Throwable $exception)
 {
     if ($this->isActive()) {
         if ($this->dispatchPreviousExceptions && $exception->getPrevious()) {
             $this->dispatchException($exception->getPrevious());
         }
         $message = new \PhpConsole\ErrorMessage();
         $message->code = $exception->getCode();
         $message->class = get_class($exception);
         $message->data = $this->dumper->dump($exception->getMessage());
         $message->file = $exception->getFile();
         $message->line = $exception->getLine();
         $message->trace = self::fetchTrace($exception->getTrace(), $message->file, $message->line);
         $this->sendMessage($message);
     }
 }
开发者ID:beardedlinuxgeek,项目名称:php-console,代码行数:20,代码来源:Errors.php

示例13: __construct

 /**
  * @param Throwable|Exception $e
  */
 public function __construct($e)
 {
     // PDOException::getCode() is a string.
     // @see http://php.net/manual/en/class.pdoexception.php#95812
     parent::__construct($e->getMessage(), (int) $e->getCode());
     $this->classname = get_class($e);
     $this->file = $e->getFile();
     $this->line = $e->getLine();
     $this->serializableTrace = $e->getTrace();
     foreach ($this->serializableTrace as $i => $call) {
         unset($this->serializableTrace[$i]['args']);
     }
     if ($e->getPrevious()) {
         $this->previous = new self($e->getPrevious());
     }
 }
开发者ID:saj696,项目名称:pipe,代码行数:19,代码来源:ExceptionWrapper.php

示例14: send

 /**
  * @param \Throwable $t
  * @throws \Comely\Framework\KernelException
  * @throws \Comely\KnitException
  */
 public function send(\Throwable $t)
 {
     $knit = (new Knit())->setTemplatePath(__DIR__)->setCompilerPath($this->kernel->getDisk("cache"));
     // Extract information from \Throwable
     $error = ["message" => null, "method" => null, "code" => $t->getCode(), "file" => $t->getFile(), "line" => $t->getLine(), "trace" => []];
     // Check if exception has "getTranslated" method
     $error["message"] = method_exists($t, "getTranslated") ? $t->getTranslated() : $t->getMessage();
     // Check if exception is child of ComelyException
     if (method_exists($t, "getMethod") && is_subclass_of($t, "ComelyException")) {
         $error["method"] = $t->getMethod();
         $error["source"] = "Component";
     } else {
         $error["method"] = get_class($t);
         $error["source"] = "Caught";
     }
     // Populate Trace
     foreach ($t->getTrace() as $trace) {
         if (Arrays::hasKeys($trace, ["function", "file", "line"])) {
             $trace["method"] = $trace["function"];
             if (isset($trace["class"])) {
                 $trace["method"] = $trace["class"] . $trace["type"] . $trace["function"];
             }
             $error["trace"][] = $trace;
         }
     }
     // Config
     $config = $this->kernel->config()->getNode("app");
     $display = ["backtrace" => $config["errorHandler"]["screen"]["debugBacktrace"] ?? false, "triggered" => $config["errorHandler"]["screen"]["triggeredErrors"] ?? false, "paths" => $config["errorHandler"]["screen"]["completePaths"] ?? false];
     // Assign values
     $knit->assign("display", $display);
     $knit->assign("error", $error);
     $knit->assign("triggered", $this->kernel->errorHandler()->fetchAll());
     $knit->assign("version", ["comely" => \Comely::VERSION, "kernel" => Kernel::VERSION, "framework" => Kernel::VERSION, "knit" => Knit::VERSION]);
     // Prepare template
     $screen = $knit->prepare("screen.knit");
     $screen = str_replace("%%knit-timer%%", number_format($screen->getTimer(), 6, ".", ""), $screen->getOutput());
     exit($screen);
 }
开发者ID:comelyio,项目名称:framework-kernel,代码行数:43,代码来源:Screen.php

示例15: createErrorHtml

 /**
  * Creates html error message
  */
 private function createErrorHtml(bool $dismissable = false)
 {
     $html = '
     <div class="alert alert-danger' . ($dismissable == true ? ' alert-dismissible' : '') . '" role="alert" id="core-error-' . $this->throwable->getCode() . '">';
     if ($dismissable) {
         $html .= '<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>';
     }
     switch (true) {
         case $this->public:
             $html .= $this->getHeadline();
             $html .= $this->getMessage();
             $html .= $this->getFileinfo();
             $html .= $this->getTrace();
             break;
         default:
             $html .= '
             <h3 class="no-top-margin">Error</h3>
             <p>Sorry for that! Webmaster has been informed. Please try again later.</p>';
     }
     $html .= '
     </div>';
     return $html;
 }
开发者ID:tekkla,项目名称:core-framework,代码行数:26,代码来源:ErrorHandler.php


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