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


PHP Throwable类代码示例

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


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

示例1: renderException

 /**
  * @param \Exception|\Throwable $e
  * @return array|null
  */
 public static function renderException($e = NULL)
 {
     if (!$e instanceof Kdyby\Autowired\Exception || !$e->getReflector()) {
         return NULL;
     }
     return ['tab' => 'Autowired', 'panel' => self::highlightException($e)];
 }
开发者ID:kdyby,项目名称:autowired,代码行数:11,代码来源:Panel.php

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

示例3: throwabeExtensions

 public function throwabeExtensions()
 {
     $t = new Throwable('Test');
     $this->assertNotEquals(array(), $t->getStackTrace());
     $t->clearStackTrace();
     $this->assertEquals(array(), $t->getStackTrace());
 }
开发者ID:Gamepay,项目名称:xp-framework,代码行数:7,代码来源:ExtensionInvocationTest.class.php

示例4: friendlyExceptionHandler

 public function friendlyExceptionHandler(\Throwable $exception)
 {
     $message = $exception->getMessage();
     $file = $exception->getFile();
     $line = $exception->getLine();
     //
     $obLevel = ob_get_level();
     if ($obLevel > 0) {
         ob_end_clean();
     }
     if (self::$_isActive) {
         echo $message;
         return;
     }
     self::$_isActive = true;
     // Log Messages
     error_log("Exception: " . $message . " in {$file} on line {$line}");
     $html = '<html lang="' . $this->_htmlLang . '"><head><meta charset="UTF-8"><title>' . $this->_escapeString($message) . '</title></head><body>';
     $html .= '<table width="100%" height="100%"><tr><td><table width="50%" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#cccccc">';
     $html .= '<tr bgcolor="#dddddd"><td height="40">' . $this->_tableTitle . '</td></tr><tr bgcolor="#ffffff"><td height="150" align="center">';
     $html .= $this->_escapeString($message);
     $html .= '</td></tr><tr bgcolor="#f2f2f2"><td height="40" align="center"><a href="/">' . $this->_backText . '</a></td></tr></table>';
     $html .= '</td></tr><tr><td height="35%"></td></tr></table></body></html>';
     echo $html;
     self::$_isActive = false;
     //
     return true;
 }
开发者ID:xueron,项目名称:pails,代码行数:28,代码来源:Debug.php

示例5: __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

示例6: handleError

/**
 * May be set as exception handler, i.e. set_exception_handler('alkemann\h2l\handleError');
 *
 * @param \Throwable $e
 */
function handleError(\Throwable $e)
{
    if ($e instanceof \alkemann\h2l\exceptions\InvalidUrl) {
        Log::info("InvalidUrl: " . $e->getMessage());
        echo (new Error(404, $e->getMessage()))->render();
        return;
    }
    if ($e instanceof \Exception) {
        Log::error(get_class($e) . ": " . $e->getMessage());
    } elseif ($e instanceof \Error) {
        Log::alert(get_class($e) . ": " . $e->getMessage());
    }
    if (DEBUG && isset($e->xdebug_message)) {
        header("Content-type: text/html");
        echo '<table>' . $e->xdebug_message . '</table><br>';
        dbp('xdebug_message');
        d($e);
    } elseif (DEBUG) {
        header("Content-type: text/html");
        echo '<h1>' . $e->getMessage() . '</h1>';
        d($e);
    } else {
        (new Error(500, $e->getMessage()))->render();
    }
}
开发者ID:alkemann,项目名称:h2l,代码行数:30,代码来源:bootstrap.php

示例7: handler

 /**
  * Throwable handler.
  *
  * @since 160711 Throwables.
  *
  * @param \Throwable $Throwable Error/Exception.
  */
 public function handler(\Throwable $Throwable)
 {
     if ($this->c::isCli()) {
         // Set `STDERR` so that it can be used in CLI feedback.
         // If debugging, `STDERR` should include a full stack trace.
         // If it's not an interactive terminal session, try to log the error.
         // The exit status should always be `1` to indicate an error.
         try {
             // Catch throwables.
             $this->c::noCacheFlags();
             $this->c::sessionWriteClose();
             $this->c::obEndCleanAll();
             if ($this->App->Config->©debug['©enable']) {
                 $this->c::writeStderr($Throwable->__toString());
             } else {
                 $this->c::writeStderr($Throwable->getMessage());
             }
             if (!$this->c::isCliInteractive()) {
                 error_log(str_replace("", '', $Throwable->__toString()));
             }
             exit(1);
             // Exit status code.
             //
         } catch (\Throwable $inner_Throwable) {
             // Edge case.
             exit(1);
             // Simply exit in this edge case.
         }
     } elseif (!headers_sent()) {
         // Send a 500 error response code.
         // If there is a throwable template, use the throwable template.
         // In either case, rethrow; i.e., allow PHP to log as an error.
         // It's also IMPORTANT to rethrow so that execution stops!
         try {
             // Catch throwables.
             $this->c::noCacheFlags();
             $this->c::sessionWriteClose();
             $this->c::obEndCleanAll();
             $this->c::statusHeader(500);
             $this->c::noCacheHeaders();
             header('content-type: text/html; charset=utf-8');
             echo $this->c::getTemplate('http/html/status/500.php')->parse(['Throwable' => $Throwable]);
             //
         } catch (\Throwable $inner_Throwable) {
             echo 'Unexpected error. Please try again.' . "\n";
             // Edge case.
         }
         throw $Throwable;
         // Rethrow. i.e., allow PHP to log as an error.
         // ↑ NOTE: Assumes throwables will not be handled here when `display_errors=yes`.
         // Therefore, when the above template is displayed, that's all you'll see in most cases.
         // i.e., Under most conditions, the display of this PHP error should not be seen. Only logged.
     } else {
         // Should be avoided. It's always better to buffer output so that an error
         // can be shown instead of what would have been output to a browser otherwise.
         // Our own template handler uses output buffering so this is not an issue with core.
         throw $Throwable;
         // Rethrow. i.e., log and/or display if debugging.
     }
 }
开发者ID:websharks,项目名称:core,代码行数:67,代码来源:Throwables.php

示例8: display

 /**
  * Display the given exception to the user.
  *
  * @param  \Exception  $exception
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function display(\Throwable $exception)
 {
     if ($this->returnJson) {
         return new JsonResponse(array('error' => $exception->getMessage(), 'file' => $exception->getFile(), 'line' => $exception->getLine()), 500);
     }
     return $this->symfony->createResponse($exception);
 }
开发者ID:jadz,项目名称:laravel-framework-4.2.18-php7,代码行数:13,代码来源:SymfonyDisplayer.php

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

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

示例11: logExceptionAndThrow

 /**
  * Handles exception error message logging if logging is enabled then re-throws the exception.
  *
  * @param LogOperation|null $log
  * @param \Throwable|\Exception $exception
  * @throws \LdapTools\Exception\LdapConnectionException
  * @throws null
  */
 protected function logExceptionAndThrow($exception, LogOperation $log = null)
 {
     if ($this->shouldLog($log) && is_null($log->getStartTime())) {
         $this->logStart($log);
     }
     if ($this->shouldLog($log)) {
         $log->setError($exception->getMessage());
     }
     throw $exception;
 }
开发者ID:ldaptools,项目名称:ldaptools,代码行数:18,代码来源:LdapOperationInvokerTrait.php

示例12: testPrepareStep

 /**
  * @dataProvider providerTestPrepareStep
  * @param HtmlHelper $helper
  * @param \Exception|\Throwable $exception
  */
 public function testPrepareStep(HtmlHelper $helper, $exception)
 {
     foreach ($exception->getTrace() as $step) {
         $colorized = $helper->prepareStep($step);
         $this->assertTrue(is_array($colorized));
         foreach (array('title', 'source', 'key', 'arguments') as $key) {
             $this->assertTrue(isset($colorized[$key]));
         }
         $this->assertTrue(is_array($colorized['arguments']));
     }
 }
开发者ID:bkrukowski,项目名称:error-dumper,代码行数:16,代码来源:HtmlHelperTest.php

示例13: exceptionHandler

 /**
  * @param \Throwable $exception
  */
 public static function exceptionHandler(\Throwable $exception)
 {
     // This error code is not included in error_reporting
     if (!error_reporting() || $exception->getLine() == 0) {
         return;
     }
     $output = new ConsoleOutput(OutputInterface::VERBOSITY_VERY_VERBOSE);
     if (!$exception instanceof \Exception) {
         $exception = new \ErrorException($exception->getMessage(), $exception->getCode(), 0, $exception->getFile(), $exception->getLine(), $exception);
         self::$application->renderException($exception, $output);
     } else {
         self::$application->renderException($exception, $output);
     }
 }
开发者ID:cawaphp,项目名称:cawa,代码行数:17,代码来源:ConsoleApp.php

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

示例15: error_log

 /**
  * 记录起始请求日志
  * 记录成功返回true,失败或没记录日志返回false
  *
  * @param  \Exception|\Throwable   $ex
  * @return  bool
  */
 public static function error_log($ex)
 {
     if (!BaseLog::isLog('error')) {
         return false;
     }
     if (!Config::getEnv("app.framework_error_log")) {
         return false;
     }
     $data = Request::nonPostParam();
     if (Config::getEnv("app.request_log_post")) {
         $data = Request::param();
     }
     $log_msg = "\r\nQP->Main最外层捕捉到Exception异常:\r\n请求参数:{Param}\r\n异常信息:{E_Msg}\r\n异常位置:{E_Point}\r\n更多异常队列信息:{E_Trace}\r\n";
     $log_data = ['Param' => json_encode($data), 'E_Msg' => $ex->getMessage(), 'E_Point' => $ex->getFile() . ":" . $ex->getLine(), 'E_Trace' => json_encode($ex->getTrace())];
     return Log::error($log_msg, $log_data, true, 'framework');
 }
开发者ID:q-phalcon,项目名称:kernel,代码行数:23,代码来源:SystemLog.php


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