本文整理汇总了PHP中ErrorException类的典型用法代码示例。如果您正苦于以下问题:PHP ErrorException类的具体用法?PHP ErrorException怎么用?PHP ErrorException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ErrorException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: catch
public static function catch($e)
{
while (ob_get_level()) {
$buf = ob_get_clean();
}
if (is_int($e)) {
$args = func_get_args();
$e = new \ErrorException($args[1], $args[0], 1, $args[2], $args[3]);
}
$type = self::$codes[$e->getCode()] ?? '';
$title = "{$type}: " . self::message($e);
$file = $e->getFile();
$line = $e->getLine();
$trace = $e->getTrace();
if (preg_match('/view\\/Engine.* eval/', $file)) {
$idx = $trace[0]['function'] === 'eval' ? 1 : 0;
$file = $trace[$idx]['args'][2];
$code = self::preview($trace[$idx]['args'][0], $line);
} elseif (is_file($file)) {
$code = self::preview(file_get_contents($file), $line);
}
$trace = self::trace($e);
include 'exception/template.php';
exit;
}
示例2: handleErrorException
/**
* @param \ErrorException $exception
*
* @return bool
*/
protected function handleErrorException(\ErrorException $exception)
{
switch ($exception->getSeverity()) {
case E_ERROR:
case E_RECOVERABLE_ERROR:
case E_CORE_ERROR:
case E_COMPILE_ERROR:
case E_USER_ERROR:
case E_PARSE:
$this->logger->error($this->buildLogMessage($exception));
break;
case E_WARNING:
case E_USER_WARNING:
case E_CORE_WARNING:
case E_COMPILE_WARNING:
$this->logger->warning($this->buildLogMessage($exception));
break;
case E_NOTICE:
case E_USER_NOTICE:
$this->logger->notice($this->buildLogMessage($exception));
break;
case E_STRICT:
case E_DEPRECATED:
case E_USER_DEPRECATED:
$this->logger->info($this->buildLogMessage($exception));
break;
}
return true;
}
示例3: it_alllows_errors_to_be_arrays
/** @test */
public function it_alllows_errors_to_be_arrays()
{
$errors = [['message' => 'Error', 'path' => '/foo']];
$exception = new ErrorException($errors, 'Error', 100);
$this->assertSame(400, $exception->getStatusCode());
$this->assertJsonStringEqualsJsonString(json_encode(['message' => 'Error', 'logref' => 100, '_embedded' => ['errors' => [['message' => 'Error', 'path' => '/foo']]]]), $exception->getHal()->asJson());
}
示例4: handleErrors
public function handleErrors(\ErrorException $e)
{
$severity = $this->determineSeverityTextValue($e->getSeverity());
$message = $e->getMessage();
$file = $e->getFile();
$line = $e->getLine();
$error = ['message' => $message, 'severity' => $severity, 'file' => $file, 'line' => $line];
return $error;
}
示例5: handleErrors
public function handleErrors(\ErrorException $e)
{
$severity = $this->determineSeverityTextValue($e->getSeverity());
$type = 'Error (' . $severity . ')';
$message = $e->getMessage();
$file = $e->getFile();
$line = $e->getLine();
return $this->getHtml($type, $message, $file, $line);
}
示例6: handle
static function handle($code, $message, $file, $line, $context)
{
echo "\n" . static::$codeMap[$code] . ': ' . $message . "\n";
echo "#0 " . $file . '(' . $line . ")\n";
$exception = new ErrorException('', $code, 0, $file, $line);
$trace = $exception->getTraceAsString();
$trace = preg_replace('~^.*?\\n|\\n.*?$~', '', $trace);
echo $trace . "\n";
return true;
}
示例7: handleErrors
public function handleErrors(\ErrorException $e)
{
$errorString = "<strong>%s</strong>: %s in <strong>%s</strong> on line <strong>%d</strong>";
$severity = $this->determineSeverityTextValue($e->getSeverity());
$error = $e->getMessage();
$file = $e->getFile();
$line = $e->getLine();
$error = sprintf($errorString, $severity, $error, $file, $line);
return $this->getTable($error);
}
示例8: handleErrors
public function handleErrors(\ErrorException $e)
{
$errorString = "%s%s in %s on line %d\n";
$severity = $this->determineSeverityTextValue($e->getSeverity());
// Let's calculate the length of the box, and set the box border.
$dashes = "\n+" . str_repeat('-', strlen($severity) + 2) . "+\n";
$severity = $dashes . '| ' . strtoupper($severity) . " |" . $dashes;
// Okay, now let's prep the message components.
$error = $e->getMessage();
$file = $e->getFile();
$line = $e->getLine();
$error = sprintf($errorString, $severity, $error, $file, $line);
return $error;
}
示例9: shutdownCheck
public static function shutdownCheck()
{
//error_log("shutdown check");
if ($error = error_get_last()) {
if ($error['type'] == E_COMPILE_ERROR) {
$exception = new ErrorException($error['message'], 0, $error['type'], $error['file'], $error['line']);
if (strpos($exception->getMessage(), "Cannot redeclare class") !== false) {
//send email alerts for duplicate class declarations.. error already logged by php
$ErrorHandler = new ErrorHandler($exception);
$ErrorHandler->email_alert();
}
}
}
return;
}
示例10: append
public function append($k, $v = null, $ifRealAppend = 'throwError')
{
if ($this->dbClass == null) {
throw new \ErrorException('thisWhere ended already');
}
if ($ifRealAppend === false) {
return $this;
}
$bakTb = $this->dbClass->_tmpObj($this->forTable);
if (empty($v) && is_array($v)) {
if ($ifRealAppend === 'markEmptyArray') {
$this->_emptyWhere[] = $k;
return $this;
} else {
$err = new \ErrorException('empty Array was Found when build where');
error_log($err->getMessage() . "\n" . $err->getTraceAsString());
throw $err;
}
}
if (is_array($k)) {
foreach ($k as $i => $v) {
if (is_numeric($i)) {
$this->append(null, $v);
} else {
$this->append($i, $v);
}
}
} elseif (is_null($k)) {
if (is_scalar($v)) {
$err = new \ErrorException();
error_log("should avoid:where->append(null,'sql-statement')\n" . $err->getTraceAsString());
$this->r[] = $v;
} else {
$tmp = trim($v->end());
if (!empty($tmp)) {
$tmp = '(' . substr($tmp, 6) . ')';
}
$this->r[] = $tmp;
}
} else {
$this->r[] = $this->conv($k, $v);
}
$this->dbClass->_tmpObj($bakTb);
return $this;
}
示例11: __construct
/**
* @param string $message
* @param int|string $http_status
* @param null $filename
* @param null $lineno
* @param \Exception $previous
*/
public function __construct($message = '', $http_status = Response::STATUS_ERROR, $filename = null, $lineno = null, \Exception $previous = null)
{
$code = 0;
$this->status = $http_status;
switch ($this->status) {
case Response::STATUS_BAD_REQUEST:
$code = 1;
break;
case Response::STATUS_METHOD_NOT_ALLOWED:
$code = 2;
break;
case Response::STATUS_ERROR:
$code = 3;
break;
}
$info = array();
if (!empty($previous)) {
$info[] = 'caught ' . get_class($previous);
}
if (!empty($filename)) {
$info[] = 'in ' . $filename;
}
if (!empty($lineno)) {
$info[] = 'at line ' . $lineno;
}
if (!empty($info)) {
$this->full_message = $message . ' [' . join(' ', $info) . ']';
} else {
$this->full_message = $message;
}
parent::__construct($message, $code, 1, is_null($filename) ? __FILE__ : $filename, is_null($lineno) ? __LINE__ : $lineno, $previous);
}
示例12: __construct
/**
* Constructor
*
* @param string The exception message
* @param integer The exception code
*/
public function __construct($message, $code, $severity, $filename, $lineno)
{
if (!$message) {
throw new $this('Unknown ' . get_class($this));
}
parent::__construct($message, $code, $severity, $filename, $lineno);
}
示例13: __construct
/**
* Constructs the exception.
* @link http://php.net/manual/en/errorexception.construct.php
* @param $message [optional]
* @param $code [optional]
* @param $severity [optional]
* @param $filename [optional]
* @param $lineno [optional]
* @param $previous [optional]
*/
public function __construct($message = '', $code = 0, $severity = 1, $filename = __FILE__, $lineno = __LINE__, \Exception $previous = null)
{
parent::__construct($message, $code, $severity, $filename, $lineno, $previous);
if (function_exists('xdebug_get_function_stack')) {
$phpCompatibleTrace = [];
$trace = array_slice(array_reverse(xdebug_get_function_stack()), 3, -1);
foreach ($trace as &$frame) {
if (!isset($frame['function'])) {
$frame['function'] = 'unknown';
}
// XDebug < 2.1.1: http://bugs.xdebug.org/view.php?id=695
if (!isset($frame['type']) || $frame['type'] === 'static') {
$frame['type'] = '::';
} elseif ($frame['type'] === 'dynamic') {
$frame['type'] = '->';
}
// XDebug has a different key name
if (isset($frame['params']) && !isset($frame['args'])) {
$frame['args'] = $frame['params'];
}
$phpCompatibleTrace[] = $frame;
}
$ref = new \ReflectionProperty('Exception', 'trace');
$ref->setAccessible(true);
$ref->setValue($this, $phpCompatibleTrace);
}
}
示例14: __construct
public function __construct($required, $code = 0, $previous = null)
{
if (is_string($required)) {
$required = array($required);
}
parent::__construct(sprintf('One or more of required ("%s") parameters is missing!', implode('", "', $required)), $code, $previous);
}
示例15: __construct
/**
* Constructor.
*
* @param string $message The Exception message to throw.
* @param int $code The Exception code.
* @param int $severity The severity level of the exception.
* @param string $filename The filename where the exception is thrown.
* @param int $line The line number where the exception is thrown.
* @param \Exception $prev The previous exception --- used for exception chaining.
*
* @throws ParseException Exception thrown with default message if none passed.
*/
public function __construct(string $message = '', int $code = 0, int $severity = 1, string $filename = __FILE__, int $line = __LINE__, \Exception $prev = null)
{
if (!$message) {
throw new $this('Unknown ' . get_class($this));
}
parent::__construct($message, $code, $severity, $filename, $line, $prev);
}