/** * 处理异常 * * @param Exception $e */ public static function handleException(\Exception $e) { restore_error_handler(); restore_exception_handler(); // clean buffer if (!headers_sent()) { ob_get_level() and ob_clean(); } $response = new Response(); try { $status = $e instanceof \Lime\Exception\NotFoundException ? 404 : 500; $response->setStatus($status); $response->setBody($status == 404 ? static::notFound($e) : static::error($e)); $response->respond(); } catch (\Exception $e) { /* 异常处理中出错的最后处理 */ ob_get_level() and ob_clean(); header('Content-Type: text/plain; charset=UTF-8', true, 500); echo static::text($e); } exit(1); }
<?php define('IS_DEV', true); require_once 'twilio.php'; if (IS_DEV) { require_once 'twillip.php'; Twillip::Start(); } $r = new Response(); if (isset($_REQUEST['Caller'])) { $r->addSay('This app uses Twillip for obviously awesome reasons!'); $r->addPlay('funky-beats.mp3', array('loop' => 3)); $r->addRedirect('/doesntexist.php'); } else { $r->addSay('Oh no! I didn\'t get sent a phone number! Who in blue blazes are you?'); $r->addSay('This line will generate a PHP warning now: ' . $_REQUEST['Caller']); } $r->respond(); if (IS_DEV) { Twillip::End(); }