本文整理汇总了PHP中Exception::getLine方法的典型用法代码示例。如果您正苦于以下问题:PHP Exception::getLine方法的具体用法?PHP Exception::getLine怎么用?PHP Exception::getLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Exception
的用法示例。
在下文中一共展示了Exception::getLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: logException
/**
* @param \Exception $e
* @param string|bool $message
* @return static
*/
public function logException(\Exception $e, $message = false)
{
$this->stream()->emptyLine();
$this->stream()->writeLine(str_repeat('*', 32));
if ($message) {
$this->stream()->emptyLine();
$this->stream()->writeLine("[31m" . $message . "[0m");
}
$this->stream()->emptyLine();
$this->stream()->writeLine("Err Message: {$e->getMessage()}");
$this->stream()->writeLine("At: {$e->getFile()}");
$this->stream()->writeLine("Line: {$e->getLine()}");
if ($e->getCode() != 0) {
$this->stream()->writeLine("Code: " . $e->getLine());
}
$this->stream()->writeLine('Stack: ');
$this->stream()->emptyLine();
foreach (explode("\n", $e->getTraceAsString()) as $line) {
$line = str_replace("\r", '', $line);
$this->stream()->writeLine(" {$line}");
}
$this->stream()->emptyLine();
$this->stream()->writeLine(str_repeat('*', 32));
$this->stream()->emptyLine();
return $this;
}
示例2: getBacktrace
/**
* Get a backtrace for an exception.
*
* Optionally limit the number of rows to include with $count, and exclude
* Psy from the trace.
*
* @param \Exception $e The exception with a backtrace.
* @param int $count (default: PHP_INT_MAX)
* @param bool $includePsy (default: true)
*
* @return array Formatted stacktrace lines.
*/
protected function getBacktrace(\Exception $e, $count = null, $includePsy = true)
{
if ($cwd = getcwd()) {
$cwd = rtrim($cwd, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
}
if ($count === null) {
$count = PHP_INT_MAX;
}
$lines = array();
$trace = $e->getTrace();
array_unshift($trace, array('function' => '', 'file' => $e->getFile() !== null ? $e->getFile() : 'n/a', 'line' => $e->getLine() !== null ? $e->getLine() : 'n/a', 'args' => array()));
if (!$includePsy) {
for ($i = count($trace) - 1; $i >= 0; $i--) {
$thing = isset($trace[$i]['class']) ? $trace[$i]['class'] : $trace[$i]['function'];
if (preg_match('/\\\\?Psy\\\\/', $thing)) {
$trace = array_slice($trace, $i + 1);
break;
}
}
}
for ($i = 0, $count = min($count, count($trace)); $i < $count; $i++) {
$class = isset($trace[$i]['class']) ? $trace[$i]['class'] : '';
$type = isset($trace[$i]['type']) ? $trace[$i]['type'] : '';
$function = $trace[$i]['function'];
$file = isset($trace[$i]['file']) ? $this->replaceCwd($cwd, $trace[$i]['file']) : 'n/a';
$line = isset($trace[$i]['line']) ? $trace[$i]['line'] : 'n/a';
$lines[] = sprintf(' <class>%s</class>%s%s() at <info>%s:%s</info>', OutputFormatter::escape($class), OutputFormatter::escape($type), OutputFormatter::escape($function), OutputFormatter::escape($file), OutputFormatter::escape($line));
}
return $lines;
}
示例3: push
/**
* @param \Exception $objEx
*/
public function push(\Exception $objEx)
{
$this->errorStackTraces[] = ['code' => $objEx->getCode(), 'file' => $objEx->getFile(), 'line' => $objEx->getLine(), 'msg' => $objEx->getMessage(), 'string' => $objEx->getTraceAsString()];
if ($this->versionType === 'dev') {
print sprintf('Exception in %s, line %s with message %s', $objEx->getFile(), $objEx->getLine(), $objEx->getMessage());
}
}
示例4: getBacktrace
/**
* Get a backtrace for an exception.
*
* Optionally limit the number of rows to include with $count, and exclude
* Psy from the trace.
*
* @param \Exception $e The exception with a backtrace.
* @param int $count (default: PHP_INT_MAX)
* @param bool $includePsy (default: true)
*
* @return array Formatted stacktrace lines.
*/
protected function getBacktrace(\Exception $e, $count = null, $includePsy = true)
{
if ($count === null) {
$count = PHP_INT_MAX;
}
$lines = array();
$trace = $e->getTrace();
array_unshift($trace, array('function' => '', 'file' => $e->getFile() != null ? $e->getFile() : 'n/a', 'line' => $e->getLine() != null ? $e->getLine() : 'n/a', 'args' => array()));
if (!$includePsy) {
for ($i = count($trace) - 1; $i >= 0; $i--) {
$thing = isset($trace[$i]['class']) ? $trace[$i]['class'] : $trace[$i]['function'];
if (preg_match('/\\\\?Psy\\\\/', $thing)) {
$trace = array_slice($trace, $i + 1);
break;
}
}
}
for ($i = 0, $count = min($count, count($trace)); $i < $count; $i++) {
$class = isset($trace[$i]['class']) ? $trace[$i]['class'] : '';
$type = isset($trace[$i]['type']) ? $trace[$i]['type'] : '';
$function = $trace[$i]['function'];
$file = isset($trace[$i]['file']) ? $trace[$i]['file'] : 'n/a';
$line = isset($trace[$i]['line']) ? $trace[$i]['line'] : 'n/a';
$lines[] = sprintf(' %s%s%s() at <info>%s:%s</info>', $class, $type, $function, $file, $line);
}
return $lines;
}
示例5: logException
/**
* @param \Exception $e
* @param string|bool $message
* @return static
*/
public function logException(\Exception $e, $message = false)
{
$this->stream()->emptyLine();
$this->stream()->write('<hr>');
if ($message) {
$this->stream()->emptyLine();
$this->stream()->writeLine($message);
}
$this->stream()->emptyLine();
$this->stream()->writeLine("Err Message: {$e->getMessage()}");
$this->stream()->writeLine("At: {$e->getFile()}");
$this->stream()->writeLine("Line: {$e->getLine()}");
if ($e->getCode() != 0) {
$this->stream()->writeLine("Code: {$e->getLine()}");
}
$this->stream()->writeLine('Stack: ');
$this->stream()->emptyLine();
$this->stream()->writeLine("<ol>");
foreach (explode("\n", $e->getTraceAsString()) as $line) {
$line = str_replace("\r", '', $line);
$this->stream()->writeLine("<li>{$line}</li>");
}
$this->stream()->writeLine("</ol>");
$this->stream()->emptyLine();
$this->stream()->write('<hr>');
$this->stream()->emptyLine();
return $this;
}
示例6: format
/**
* If detailed errors are enabled, just format the exception into
* a simple error message and display it.
*
* @param \Exception $exception
* @param boolean $isCli
*
* @return string
*/
public static function format(\Exception $exception, $isCli = false)
{
if ($isCli === true) {
return "+++ Untreated Exception +++" . PHP_EOL . "Message: " . $exception->getMessage() . PHP_EOL . "Location: " . $exception->getFile() . " on line " . $exception->getLine() . PHP_EOL . "Stack Trace: " . PHP_EOL . $exception->getTraceAsString() . PHP_EOL;
}
return "<html>\n <head>\n <style>\n pre { display: block;\n padding: 8.5px;\n margin: 0 0 9px;\n line-height: 18px;\n word-break: break-all;\n word-wrap: break-word;\n white-space: pre;\n white-space: pre-wrap;\n border: 1px solid #ccc;\n border: 1px solid rgba(0, 0, 0, 0.15);\n -webkit-border-radius: 4px;\n -moz-border-radius: 4px;\n border-radius: 6px;\n color: chartreuse;\n background-color: black;\n }\n </style>\n </head>\n <h2>Untreated Exception</h2>\n <h3>Message:</h3>\n <pre>" . $exception->getMessage() . "</pre>\n <h3>Location:</h3>\n <pre>" . $exception->getFile() . " on line " . $exception->getLine() . "</pre>\n <h3>Stack Trace:</h3>\n <pre>" . $exception->getTraceAsString() . "</pre></html>";
}
示例7: getFilteredStacktrace
/**
* Filters stack frames from PHPUnit classes.
*
* @param Exception $e
* @param boolean $filterTests
* @param boolean $asString
* @return string
*/
public static function getFilteredStacktrace(Exception $e, $filterTests = TRUE, $asString = TRUE)
{
if ($asString === TRUE) {
$filteredStacktrace = '';
} else {
$filteredStacktrace = array();
}
$groups = array('DEFAULT');
if (!defined('PHPUNIT_TESTSUITE')) {
$groups[] = 'PHPUNIT';
}
if ($filterTests) {
$groups[] = 'TESTS';
}
$eTrace = $e->getTrace();
if (!self::frameExists($eTrace, $e->getFile(), $e->getLine())) {
array_unshift($eTrace, array('file' => $e->getFile(), 'line' => $e->getLine()));
}
foreach ($eTrace as $frame) {
if (isset($frame['file']) && is_file($frame['file']) && !PHP_CodeCoverage::getInstance()->filter()->isFiltered($frame['file'], $groups, TRUE)) {
if ($asString === TRUE) {
$filteredStacktrace .= sprintf("%s:%s\n", $frame['file'], isset($frame['line']) ? $frame['line'] : '?');
} else {
$filteredStacktrace[] = $frame;
}
}
}
return $filteredStacktrace;
}
示例8: getFilteredStacktrace
/**
* Filters stack frames from PHPUnit classes.
*
* @param Exception $e
* @param boolean $asString
* @return string
*/
public static function getFilteredStacktrace(Exception $e, $asString = TRUE)
{
if (!defined('PHPUNIT_TESTSUITE')) {
$blacklist = PHPUnit_Util_GlobalState::phpunitFiles();
} else {
$blacklist = array();
}
if ($asString === TRUE) {
$filteredStacktrace = '';
} else {
$filteredStacktrace = array();
}
if ($e instanceof PHPUnit_Framework_SyntheticError) {
$eTrace = $e->getSyntheticTrace();
} else {
$eTrace = $e->getTrace();
}
if (!self::frameExists($eTrace, $e->getFile(), $e->getLine())) {
array_unshift($eTrace, array('file' => $e->getFile(), 'line' => $e->getLine()));
}
foreach ($eTrace as $frame) {
if (isset($frame['file']) && is_file($frame['file']) && !isset($blacklist[$frame['file']])) {
if ($asString === TRUE) {
$filteredStacktrace .= sprintf("%s:%s\n", $frame['file'], isset($frame['line']) ? $frame['line'] : '?');
} else {
$filteredStacktrace[] = $frame;
}
}
}
return $filteredStacktrace;
}
示例9: format
/**
* If detailed errors are enabled, just format the exception into
* a simple error message and display it.
*
* @param \Exception $exception
*
* @return string
*/
public static function format(\Exception $exception)
{
if (Sapi::isCli()) {
return "+++ Untreated Exception +++" . PHP_EOL . "Message: " . $exception->getMessage() . PHP_EOL . "Location: " . $exception->getFile() . " on line " . $exception->getLine() . PHP_EOL . "Stack Trace: " . PHP_EOL . $exception->getTraceAsString() . PHP_EOL;
}
return "<html><h2>Untreated Exception</h2>\n <h3>Message:</h3>\n <pre>" . $exception->getMessage() . "</pre>\n <h3>Location:</h3>\n <pre>" . $exception->getFile() . " on line " . $exception->getLine() . "</pre>\n <h3>Stack Trace:</h3>\n <pre>" . $exception->getTraceAsString() . "</pre></html>";
}
示例10: showException
/**
* Show exception screen
*
* @param \Exception $exception
*/
public function showException(\Exception $exception)
{
@ob_end_clean();
$msg = sprintf("%s\nFile: %s\nLine: %d\nTrace:\n%s", $exception->getMessage(), $exception->getFile(), $exception->getLine(), $exception->getTraceAsString());
\Kalibri::logger()->add(Logger::L_EXCEPTION, $msg);
$viewName = \Kalibri::config()->get('error.view.exception');
if ($viewName) {
$view = new \Kalibri\View($viewName);
$view->ex = $exception;
$str = '';
$file = \fopen($exception->getFile(), 'r');
for ($i = 0; $i < $exception->getLine() - 16; $i++) {
\fgets($file);
}
for ($i = 0; $i < 20; $i++) {
$str .= \fgets($file);
}
$view->code = Highlight::php($str, true, 1, $exception->getLine());
if ($view->isExists()) {
$view->render();
} else {
// Fallback to show any message in case if exception view not found or not set
echo "<h1>Exception</h1><p>{$exception->getMessage()}</p>";
}
}
exit;
}
示例11: getCauseMessage
/**
* Function must be public to call on caused exceptions
*
* @param array
* @return string
*/
function getCauseMessage(&$causes)
{
$trace = $this->getTrace();
$cause = array('class' => get_class($this), 'message' => $this->getMessage(), 'file' => 'unknown', 'line' => 'unknown');
if (isset($trace[0])) {
if (isset($trace[0]['file'])) {
$cause['file'] = $trace[0]['file'];
$cause['line'] = $trace[0]['line'];
}
}
$causes[] = $cause;
if ($this->cause instanceof Exception) {
$this->cause->getCauseMessage($causes);
} elseif ($this->cause instanceof Exception) {
$causes[] = array('class' => get_class($this->cause), 'message' => $this->cause->getMessage(), 'file' => $this->cause->getFile(), 'line' => $this->cause->getLine());
}
if (is_array($this->cause)) {
foreach ($this->cause as $cause) {
if ($cause instanceof Exception || $cause instanceof Exception) {
$cause->getCauseMessage($causes);
} elseif ($cause instanceof Exception) {
$causes[] = array('class' => get_class($cause), 'message' => $cause->getMessage(), 'file' => $cause->getFile(), 'line' => $cause->getLine());
} elseif (is_array($cause) && isset($cause['message'])) {
// PEAR_ErrorStack warning
$causes[] = array('class' => $cause['package'], 'message' => $cause['message'], 'file' => isset($cause['context']['file']) ? $cause['context']['file'] : 'unknown', 'line' => isset($cause['context']['line']) ? $cause['context']['line'] : 'unknown');
} else {
$causes[] = array('class' => null, 'message' => $cause, 'file' => null, 'line' => null);
}
}
}
}
示例12: exceptionHandler
/**
* @param \Exception $e
* @return bool
*/
function exceptionHandler(\Exception $e)
{
echo '<h1>Error</h1><p>Sorry, the script died with a exception</p>';
echo $e->getMessage() . ' in <br>' . $e->getFile() . ': <br>' . $e->getLine(), ' : <br>', __FUNCTION__, ' : <br>', $e->getTraceAsString();
log::error($e->getMessage() . ' in ' . $e->getFile() . ':' . $e->getLine() . "<br>\n", "Code: " . $e->getCode(), $e->getTrace());
mail(ADMIN_MAIL, '[GitReminder] System got locked', $e->getMessage() . ' in ' . $e->getFile() . ':' . $e->getLine() . "\n\n" . "Funktion -> " . __FUNCTION__ . $e->getTraceAsString() . "\n\n" . "Code: " . $e->getCode());
@trigger_error('', E_USER_ERROR);
}
示例13: handleException
public function handleException(Exception $exception)
{
$msg = "Uncaught Exception: " . $exception->getMessage() . "\n";
$msg .= $exception->getMessage() . "\n";
$msg .= 'Line: ' . $exception->getLine() . " in " . $exception->getFile();
$msg .= "\n\nTrace Summary:\n" . self::traceFormat($exception->getTrace());
if (ERROR_DISPLAY_MODE == 'html') {
$msg .= "\nFull Trace: \n" . print_r($exception->getTrace(), 1);
}
$this->show($msg, $exception->getFile(), $exception->getLine(), $exception->getCode(), 'E_WARNING');
}
示例14: exceptionMessage
/**
* @description Build message
*
* @return string
*/
public function exceptionMessage()
{
$msg = '';
if ($this->exception->getCode()) {
$msg .= "Exception code: " . $this->exception->getCode() . PHP_EOL;
}
$msg .= $this->exception->getMessage() . PHP_EOL;
$msg .= "At file: " . $this->exception->getFile();
$msg .= ": " . $this->exception->getLine() . PHP_EOL;
$msg .= "Trace: " . PHP_EOL . $this->exception->getTraceAsString();
return $msg;
}
示例15: log_original_exception_message
/**
* Logs the original exception message.
*
* Provided as a manual override over the default `WP_DEBUG` dependent behaviour.
*
* @see Tribe__Exception::handle()
*
* @return bool `true` if the message was logged, `false` otherwise.
*/
private function log_original_exception_message()
{
if (!class_exists('Tribe__Log')) {
return false;
}
$logger = new Tribe__Log();
$message = $this->original_exception->getMessage();
$log_type = $this->get_log_type_for_exception_code($this->original_exception->getCode());
$src = $this->original_exception->getFile() . ':' . $this->original_exception->getLine();
$logger->log($message, $log_type, $src);
return true;
}