function showException($exception) { $output = '<h1>' . $exception->getMessage() . '</h1>'; $output .= '<p>' . nl2br($exception->getTraceAsString()) . '</p>'; if ($previous = $exception->getPrevious()) { $output = showException($previous) . $output; } return $output; }
function showException($exception) { $output = '<h1>' . $exception->getMessage() . '</h1>'; $output .= '<p>' . nl2br($exception->getTraceAsString()) . '</p>'; if ($exception instanceof \Lysine\Exception && ($more = $exception->getMore())) { $output .= '<h2>More Information</h2>'; $output .= '<pre>' . var_export($more, true) . '</pre>'; } if ($previous = $exception->getPrevious()) { $output = showException($previous) . $output; } return $output; }
/** * 实际的异常处理函数 * @param Exception $e 异常对象 * @return void */ function exceptionHandler($e) { if ($e instanceof MY_Exception) { showException($e->getMessage(), $e->getRedirectUri(), $e->getRedirectTime(), $e->getHeading(), $e->getStatusCode()); } else { if ($e instanceof HTTPException) { showException($e->getMessage(), null, null, 'HTTP Error', $e->getCode()); } else { showException($e->getMessage()); } } }
* Use Rho to infinitely retry getting our IP from ifconfig.me, * until the script is killed with Ctrl+C */ require "../vendor/autoload.php"; use Rho\Exception; use Rho\Transport\HttpJsonTransport; use Rho\Retrier; use Rho\RateLimiter\SimpleRateLimiter; use Rho\Exception\TooManyRetriesException; use Monolog\Logger; function showException($e) { echo $e->getMessage() . "\n"; } $logger = new Logger('ifconfig'); $client = new HttpJsonTransport("http://ifconfig.me", ['logger' => $logger]); $client = SimpleRateLimiter::wrap($client, ['logger' => $logger, 'limits' => [10 => 1]]); // limit to 1 request every 10s $client = Retrier::wrap($client, ['logger' => $logger, 'delay' => 0.5]); // retry forever with 0.5s delay try { $resp = $client->rpc(['GET', '/all.json'], [], ['timeout' => 5, 'connect_timeout' => 5]); if (!$resp->isError()) { $data = $resp->getResult(); echo "Your IP is {$data['ip_addr']}\n"; } else { echo "API Server error\n"; } } catch (TooManyRetriesException $e) { showException($e); }
<?php clearstatcache(); require_once 'Helper.php'; require_once 'Autoloader.php'; // require_once 'Swift/swift_required.php'; // require_once 'facebook/facebook.php'; if (true === $debug) { error_reporting(-1); set_exception_handler(function ($exception) { showException($exception); }); set_error_handler(function ($type, $message, $file, $line) { $exception = new ErrorException($message, $type, 0, $file, $line); showException($exception); }); register_shutdown_function(function () { $error = error_get_last(); showException($error); }); } define('MB_STRING', (int) function_exists('mb_get_info')); // Thin\Autoloader::registerNamespace('ThinEntity', APPLICATION_PATH . DS . 'entities'); spl_autoload_register('Thin\\Autoloader::autoload');