本文整理汇总了PHP中exception类的典型用法代码示例。如果您正苦于以下问题:PHP exception类的具体用法?PHP exception怎么用?PHP exception使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了exception类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: panic
public static function panic(\exception $e)
{
$response = Factory::make("response");
$vars = [];
$vars['message'] = $e->getMessage();
$vars['file_line'] = $e->getFile() . " " . $e->getLine();
$response->renderHtml("exception.html", $vars);
}
示例2: generic_display_error
/**
* Static s_display_error
*/
static function generic_display_error(exception $ex)
{
$title = $ex->getMessage();
$err_no = $ex->getCode();
if (!class_exists('loader') || class_exists('loader') && !loader::in_ajax()) {
header('', true, 500);
$message = '<style>* {font: 0.97em verdana;} a {text-decoration:none;background:#EFEFEF;padding:4px;} a:hover{background: red;}</style><h1>Ups! We have an error here.</h1>';
$subject = "Error " . " at " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$message .= 'Visit <a href="/">index</a> page.<br/><br/>';
echo $message;
// if debug
if (class_exists('core') && core::is_debug()) {
echo '<br/>Error : ' . $title . ' : ' . $err_no;
echo '<br/><br/>' . nl2br($ex->getTraceAsString());
}
}
}
示例3: import
/**
* 文件导入
*/
public static function import($className, $type)
{
static $_file = array();
//特殊字符转换
$type = strtolower($type);
if (isset($_file[$className])) {
return true;
}
//判断文件类型 1=>action 2=>model -1=>其他文件
$filetype = $type == 'action' ? 1 : ($type == 'model' ? 2 : -1);
$flag = false;
if ($filetype == 1) {
$flag = self::importAction($className);
} else {
if ($filetype == 2) {
$flag = self::importModel($className);
} else {
$flag = self::importOther($className);
}
}
if (!$flag) {
exception::halt(FILE_NOTFOUND, '文件:' . $className . '未找到');
}
}
示例4: errorAction
/**
* Show YAF Error
* only display errors under DEV, else save error in LOG_FILE
* @param exception $exception
* @return void
*/
public function errorAction($exception)
{
switch ($exception->getCode()) {
case YAF_ERR_NOTFOUND_MODULE:
case YAF_ERR_NOTFOUND_CONTROLLER:
case YAF_ERR_NOTFOUND_ACTION:
case YAF_ERR_NOTFOUND_VIEW:
if (ENV == 'DEV') {
echo 404, ":", $exception->getMessage();
} else {
echo 404;
file_put_contents(LOG_FILE, $exception->getMessage() . PHP_EOL, FILE_APPEND);
}
break;
default:
if (ENV == 'DEV') {
echo 0, ":", $exception->getMessage();
} else {
echo 'Unknown error';
file_put_contents(LOG_FILE, $exception->getMessage() . PHP_EOL, FILE_APPEND);
}
break;
}
}
示例5: addExceptionToScore
private function addExceptionToScore(\exception $exception)
{
list($file, $line) = $this->getBacktrace($exception->getTrace());
$this->score->addException($file, $this->class, $this->currentMethod, $line, $exception);
return $this;
}
示例6: error_message
/**
* Converts a Stripe exception into an error message.
*
* @param exception $exception
*
* @return string Error message.
*/
public static function error_message($exception)
{
if ($exception instanceof Stripe_CardError) {
$body = $exception->getJsonBody();
$error = $body['error'];
return sprintf(_x('Error code: <code>%1$s</code>. %2$s.', 's2member-front', 's2member'), esc_html(trim($error['code'], '.')), esc_html(trim($error['message'], '.')));
}
if ($exception instanceof Stripe_InvalidRequestError) {
return _x('Invalid parameters to Stripe; please contact the site owner.', 's2member-front', 's2member');
}
if ($exception instanceof Stripe_AuthenticationError) {
return _x('Invalid Stripe API keys; please contact the site owner.', 's2member-front', 's2member');
}
if ($exception instanceof Stripe_ApiConnectionError) {
return _x('Network communication failure with Stripe; please try again.', 's2member-front', 's2member');
}
if ($exception instanceof Stripe_Error) {
return _x('Stripe API error; please try again.', 's2member-front', 's2member');
}
return _x('Stripe error; please try again.', 's2member-front', 's2member');
}
示例7: testRun
public function testRun()
{
$this->given($pusher = new testedClass(__FILE__), $pusher->setTaggerEngine($taggerEngine = new \mock\mageekguy\atoum\scripts\tagger\engine()), $pusher->setGit($git = new \mock\mageekguy\atoum\cli\commands\git()), $pusher->setErrorWriter($errorWriter = new \mock\mageekguy\atoum\writers\std\err()), $pusher->setInfoWriter($infoWriter = new \mock\mageekguy\atoum\writers\std\out()), $this->calling($infoWriter)->write = $infoWriter)->assert('Pusher should write error if tag file is not readable')->if($this->calling($errorWriter)->write = $errorWriter, $this->function->file_get_contents = false)->then->object($pusher->run())->isIdenticalTo($pusher)->mock($errorWriter)->call('write')->withArguments('Unable to read \'' . $pusher->getTagFile() . '\'')->once()->assert('Pusher should write error if tag file is not writable')->if($this->calling($errorWriter)->write = $errorWriter, $this->function->file_put_contents = false, $this->function->file_get_contents = '0.0.0')->then->object($pusher->run())->isIdenticalTo($pusher)->mock($errorWriter)->call('write')->withArguments('Unable to write in \'' . $pusher->getTagFile() . '\'')->once()->assert('Pusher should tag code and commit it if tag file is writable')->if($this->function->file_put_contents = function ($path, $data) {
return strlen($data);
}, $this->calling($taggerEngine)->tagVersion->doesNothing(), $this->calling($git)->addAllAndCommit = $git, $this->calling($git)->checkoutAllFiles = $git, $this->calling($git)->createTag = $git, $this->calling($git)->push = $git, $this->calling($git)->forcePush = $git, $this->calling($git)->pushTag = $git, $this->calling($git)->resetHardTo = $git, $this->calling($git)->deleteLocalTag = $git)->then->object($pusher->run())->isIdenticalTo($pusher)->function('file_put_contents')->wasCalledWithArguments($pusher->getTagFile(), '0.0.1')->once()->mock($taggerEngine)->call('tagVersion')->before($this->mock($git)->call('addAllAndCommit')->withArguments('Set version to 0.0.1.')->before($this->mock($git)->call('createTag')->withArguments('0.0.1')->before($this->mock($git)->call('push')->withArguments($pusher->getRemote())->once())->before($this->mock($git)->call('pushTag')->withArguments('0.0.1', $pusher->getRemote())->once())->once())->once())->after($this->mock($taggerEngine)->call('setSrcDirectory')->withArguments($pusher->getWorkingDirectory())->once())->after($this->mock($taggerEngine)->call('setVersion')->withArguments('$Rev:' . ' 0.0.1 $')->once())->once()->call('tagVersion')->before($this->mock($git)->call('addAllAndCommit')->withArguments('Set version to dev-master.')->once())->after($this->mock($taggerEngine)->call('setSrcDirectory')->withArguments($pusher->getWorkingDirectory())->once())->after($this->mock($taggerEngine)->call('setVersion')->withArguments('$Rev:' . ' dev-master $')->once())->once()->if($pusher->tagPatchVersion())->then->object($pusher->run())->isIdenticalTo($pusher)->function('file_put_contents')->wasCalledWithArguments($pusher->getTagFile(), '0.0.1')->twice()->if($pusher->tagMinorVersion())->then->object($pusher->run())->isIdenticalTo($pusher)->function('file_put_contents')->wasCalledWithArguments($pusher->getTagFile(), '0.1.0')->once()->if($pusher->tagMajorVersion())->then->object($pusher->run())->isIdenticalTo($pusher)->function('file_put_contents')->wasCalledWithArguments($pusher->getTagFile(), '1.0.0')->once()->assert('Pusher should write error if pushing tag failed and should try to reset repository')->if($pusher->tagPatchVersion(), $this->calling($git)->pushTag->throw = $exception = new \exception(uniqid()))->then->object($pusher->run())->isIdenticalTo($pusher)->mock($errorWriter)->call('write')->withArguments($exception->getMessage())->once()->mock($git)->call('resetHardTo')->withArguments('HEAD~2')->once()->call('deleteLocalTag')->withArguments('0.0.1')->once()->assert('Pusher should write error if pushing commit failed and should try to reset repository')->if($this->calling($git)->push->throw = $exception = new \exception(uniqid()))->then->object($pusher->run())->isIdenticalTo($pusher)->mock($errorWriter)->call('write')->withArguments($exception->getMessage())->once()->mock($git)->call('resetHardTo')->withArguments('HEAD~2')->once()->call('deleteLocalTag')->withArguments('0.0.1')->once()->assert('Pusher should write error if pushing commit for DEVELOPMENT version failed and should try to reset repository')->if($this->calling($git)->push = $git, $this->calling($git)->addAllAndCommit[2]->throw = $exception = new \exception(uniqid()))->then->object($pusher->run())->isIdenticalTo($pusher)->mock($errorWriter)->call('write')->withArguments($exception->getMessage())->once()->mock($git)->call('resetHardTo')->withArguments('HEAD~1')->once()->assert('Pusher should write error if pushing commit for DEVELOPMENT version failed and should try to reset repository')->if($this->calling($git)->createTag->throw = $exception = new \exception(uniqid()))->then->object($pusher->run())->isIdenticalTo($pusher)->mock($errorWriter)->call('write')->withArguments($exception->getMessage())->once()->mock($git)->call('resetHardTo')->withArguments('HEAD~1')->once()->assert('Pusher should write error if commit failed for STABLE version and should try to reset repository')->if($this->calling($git)->createTag = $git, $this->calling($git)->addAllAndCommit[1]->throw = $exception = new \exception(uniqid()))->then->object($pusher->run())->isIdenticalTo($pusher)->mock($errorWriter)->call('write')->withArguments($exception->getMessage())->after($this->mock($git)->call('addAllAndCommit'))->once()->mock($git)->call('checkoutAllFiles')->after($this->mock($git)->call('addAllAndCommit'))->once()->assert('Pusher should write error if reset failed')->if($this->calling($git)->checkoutAllFiles->throw = $checkoutAllFilesException = new \exception(uniqid()))->then->object($pusher->run())->isIdenticalTo($pusher)->mock($errorWriter)->call('write')->withArguments($checkoutAllFilesException->getMessage())->once();
}
示例8: send_error
/**
* Send the error information to the WS client
* formatted as XML document.
* @param exception $ex
* @return void
*/
protected function send_error($ex = null)
{
// Zend Soap server fault handling is incomplete compared to XML-RPC :-(
// we can not use: echo $this->zend_server->fault($ex);
//TODO: send some better response in XML
if ($ex) {
$info = $ex->getMessage();
if (debugging() and isset($ex->debuginfo)) {
$info .= ' - ' . $ex->debuginfo;
}
} else {
$info = 'Unknown error';
}
$xml = '<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body><SOAP-ENV:Fault>
<faultcode>MOODLE:error</faultcode>
<faultstring>' . $info . '</faultstring>
</SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>';
$this->send_headers();
header('Content-Type: application/xml; charset=utf-8');
header('Content-Disposition: inline; filename="response.xml"');
echo $xml;
}
示例9: handle_exception
/**
* Displays an exception in HTML, and exists. Includes the exception
* trace in an HTML comment, and a readable error string along with the
* exception message.
* @param exception $e Exception
*/
public static function handle_exception($e)
{
// Display actual trace in HTML comment. There shouldn't be any
// security-sensitive information in the trace, so this can be
// displayed even on live server (I hope).
if (debugging('', DEBUG_DEVELOPER)) {
global $CFG;
print "<pre class='forumng-stacktrace'>";
print htmlspecialchars(str_replace($CFG->dirroot, '', $e->getTraceAsString()));
print "</pre>";
} else {
print "<!--\n";
print $e->getTraceAsString();
// Not escaped, I think this is correct...
print "\n-->";
}
// Make a short version of the trace string for log
$minitrace = self::get_minitrace_part($e->getFile(), $e->getLine());
foreach ($e->getTrace() as $entry) {
$minitrace .= ' ' . self::get_minitrace_part($entry['file'], $entry['line']);
}
$minitrace = shorten_text($minitrace, 120, true);
$message = shorten_text($e->getMessage(), 120, true);
global $FULLME, $USER, $CFG;
$url = str_replace($CFG->wwwroot . '/mod/forumng/', '', $FULLME);
add_to_log(0, 'forumng', 'error', $url, "{$message} / {$minitrace}", 0, $USER->id);
// Error to user with just the message
print_error('error_exception', 'forumng', '', $e->getMessage());
}
示例10: log
/**
* Virhelogi
*
* @param string $message Virheviesti
* @param exception $exception Exception
* @param string $type Kirjataanko tuote vai tilauslogiin
*/
public function log($message, $exception = '', $type = 'product')
{
if (self::LOGGING == true) {
$timestamp = date('d.m.y H:i:s');
$message = utf8_encode($message);
if ($exception != '') {
$message .= " (" . $exception->getMessage() . ") faultcode: " . $exception->faultcode;
}
$message .= "\n";
$log_location = $type == 'product' ? '/tmp/magento_log.txt' : '/tmp/magento_order_log.txt';
error_log("{$timestamp}: {$message}", 3, $log_location);
}
}
示例11: text
/**
* Get a single line of text representing the exception:
*
* Error [ Code ]: Message ~ File [ Line ]
*
* @param object Exception
* @return string
*/
public static function text(exception $e)
{
return sprintf('Message: %s ERROR: %s Code:[ %s ] Fiel: %s ~ Line [ %d ]', strip_tags($e->getMessage()), get_class($e), $e->getCode(), $e->getFile(), $e->getLine());
}
示例12: addErrorToDisplay
/**
* adds a exception to the array of displayed exceptions for the view
* by default is displayed in the inc_header, but with the custom destination set to true
* the exception won't be displayed by default but can be displayed where ever wanted in the tpl
*
* @param exception $oEr a exception object or just a language local (string) which will be converted into a oxExceptionToDisplay object
* @param bool $blFull if true the whole object is add to display (default false)
* @param bool $blCustomDestination true if the exception shouldn't be displayed at the default position (default false)
* @param string $sCustomDestination defines a name of the view variable containing the messages, overrides Parameter 'CustomError' ("default")
* @param string $sActiveController defines a name of the controller, which should handle the error.
*/
public function addErrorToDisplay($oEr, $blFull = false, $blCustomDestination = false, $sCustomDestination = "", $sActiveController = "")
{
if ($blCustomDestination && (oxRegistry::getConfig()->getRequestParameter('CustomError') || $sCustomDestination != '')) {
// check if the current request wants do display exceptions on its own
$sDestination = oxRegistry::getConfig()->getRequestParameter('CustomError');
if ($sCustomDestination != '') {
$sDestination = $sCustomDestination;
}
} else {
//default
$sDestination = 'default';
}
//starting session if not yet started as all exception
//messages are stored in session
$oSession = $this->getSession();
if (!$oSession->getId() && !$oSession->isHeaderSent()) {
$oSession->setForceNewSession();
$oSession->start();
}
$aEx = oxRegistry::getSession()->getVariable('Errors');
if ($oEr instanceof oxException) {
$oEx = oxNew('oxExceptionToDisplay');
$oEx->setMessage($oEr->getMessage());
$oEx->setExceptionType(get_class($oEr));
if ($oEr instanceof oxSystemComponentException) {
$oEx->setMessageArgs($oEr->getComponent());
}
$oEx->setValues($oEr->getValues());
$oEx->setStackTrace($oEr->getTraceAsString());
$oEx->setDebug($blFull);
$oEr = $oEx;
} elseif ($oEr && !$oEr instanceof oxIDisplayError) {
// assuming that a string was given
$sTmp = $oEr;
$oEr = oxNew('oxDisplayError');
$oEr->setMessage($sTmp);
} elseif ($oEr instanceof oxIDisplayError) {
// take the object
} else {
$oEr = null;
}
if ($oEr) {
$aEx[$sDestination][] = serialize($oEr);
oxRegistry::getSession()->setVariable('Errors', $aEx);
if ($sActiveController == '') {
$sActiveController = oxRegistry::getConfig()->getRequestParameter('actcontrol');
}
if ($sActiveController) {
$aControllerErrors[$sDestination] = $sActiveController;
oxRegistry::getSession()->setVariable('ErrorController', $aControllerErrors);
}
}
}
示例13: handle_exceptions
/**
* Function handle_exceptions
*
* * @param exception $e
* @return void
*/
function handle_exceptions(exception $e)
{
global $msg;
$trace = $e->getTrace();
file_put_contents(_LOG_PATH_ . 'admin.exception.log', print_r($trace, true), FILE_APPEND);
$msg .= $e->getMessage();
return 'logout';
}
示例14: __construct
public function __construct($message, $engmessage, $data = NULL)
{
parent::__construct($message);
if (!is_null($data)) {
$this->data = $data;
}
}
示例15: __construct
public function __construct ($message = null, $code = 0)
{
parent::__construct($message, $code);
$this->stage = coren::current_stage ();
$this->module = coren::current_module();
$this->method = coren::current_method();
}