Arquivos
hhvm/hphp/system/classes/exception.php
T
Mike Magruder ac9665e148 Remove old vestiges of frame injection.
Nuke a little dead code that is leftovers of the old frame injection goo.
2013-04-23 09:52:57 -07:00

348 linhas
10 KiB
PHP

<?php
// Do NOT modifiy this doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/class.exception.php )
*
* Exception is the base class for all Exceptions.
*
*/
class Exception {
protected $message = ''; // exception message
protected $code = 0; // user defined exception code
protected $previous = null;
protected $file; // source filename of exception
protected $line; // source line of exception
protected $trace; // full stacktrace
private $inited = false;
private static $traceOpts = false;
/**
* This cannot be implemented in __construct, because a derived class may
* implement its own __construct, losing the stacktrace. The runtime has
* special logic to call the __init__ method on instances of Exception before
* calling __construct just to make sure $this->trace is always populated.
*/
final function __init__() {
if ($this->inited) {
return;
}
$this->initTrace();
$this->inited = true;
}
function __construct($message = '', $code = 0, Exception $previous = null) {
$this->message = $message;
$this->code = $code;
$this->previous = $previous;
}
// Do NOT modifiy this doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/exception.getmessage.php )
*
* Returns the Exception message.
*
* @return mixed Returns the Exception message as a string.
*/
function getMessage() {
return $this->message;
}
// Do NOT modifiy this doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/exception.getprevious.php )
*
* Returns the previous Exception.
*
* @return mixed Returns the previous Exception if available or NULL otherwise.
*/
final function getPrevious() {
return $this->previous;
}
final function setPrevious(Exception $previous) {
$this->previous = $previous;
}
final function setPreviousChain(Exception $previous) {
$cur = $this;
$next = $cur->getPrevious();
while ($next instanceof Exception) {
$cur = $next;
$next = $cur->getPrevious;
}
$cur->setPrevious($previous);
}
// Do NOT modifiy this doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/exception.getcode.php )
*
* Returns the Exception code.
*
* @return mixed Returns the Exception code as a integer.
*/
function getCode() {
return $this->code;
}
// Do NOT modifiy this doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/exception.getfile.php )
*
* Get the name of the file the exception was thrown from.
*
* @return mixed Returns the filename in which the exception was
* thrown.
*/
final function getFile() {
return $this->file;
}
// Do NOT modifiy this doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/exception.getline.php )
*
* Returns line number where the exception was thrown.
*
* @return mixed Returns the line number where the exception was
* thrown.
*/
final function getLine() {
return $this->line;
}
// Do NOT modifiy this doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/exception.gettrace.php )
*
* Returns the Exception stack trace.
*
* @return mixed Returns the Exception stack trace as an array.
*/
final function getTrace() {
return $this->trace;
}
// Do NOT modifiy this doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/exception.gettraceasstring.php )
*
* Returns the Exception stack trace as a string.
*
* @return mixed Returns the Exception stack trace as a string.
*/
final function getTraceAsString() {
$i = 0;
$s = "";
foreach ($this->getTrace() as $frame) {
if (!is_array($frame)) continue;
$s .= "#$i " .
(isset($frame['file']) ? $frame['file'] : "") . "(" .
(isset($frame['line']) ? $frame['line'] : "") . "): " .
(isset($frame['class']) ? $frame['class'] . $frame['type'] : "") .
$frame['function'] . "()\n";
$i++;
}
$s .= "#$i {main}";
return $s;
}
/* Overrideable */
// formated string for display
function __toString() {
return "exception '" . get_class($this) . "' with message '" .
$this->getMessage() . "' in " . $this->getFile() . ":" .
$this->getLine() . "\nStack trace:\n" . $this->getTraceAsString();
}
/**
* Derived classes may override the methods below if different behavior
* for initializing the trace is desired
*/
protected function initTrace() {
$this->trace = debug_backtrace(static::getTraceOptions());
// Remove top stack frames up to and including Exception::__init__,
// set the 'file' and 'line' properties appropriately
while (!empty($this->trace)) {
$top = array_shift($this->trace);
if (isset($top['class']) && isset($top['function']) &&
strcasecmp($top['class'], 'exception') === 0 &&
strcasecmp($top['function'], '__init__') === 0) {
if (isset($top['file'])) $this->file = $top['file'];
if (isset($top['line'])) $this->line = $top['line'];
return;
}
}
}
public static function getTraceOptions() {
return self::$traceOpts;
}
public static function setTraceOptions($opts) {
self::$traceOpts = $opts;
}
}
// Do NOT modifiy this doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/class.logicexception.php )
*
* Exception thrown if a logic expression is invalid
*
*/
class LogicException extends Exception {}
// Do NOT modifiy this doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from
* http://php.net/manual/en/class.badfunctioncallexception.php )
*
* Exception thrown if a callback refers to an undefined function or if
* some arguments are missing
*
*/
class BadFunctionCallException extends LogicException {}
// Do NOT modifiy this doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/class.badmethodcallexception.php
* )
*
* Exception thrown if a callback refers to an undefined method or if some
* arguments are missing
*
*/
class BadMethodCallException extends BadFunctionCallException {}
// Do NOT modifiy this doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/class.domainexception.php )
*
* Exception thrown if a value does not adhere to a defined valid data
* domain
*
*/
class DomainException extends LogicException {}
// Do NOT modifiy this doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from
* http://php.net/manual/en/class.invalidargumentexception.php )
*
* Exception thrown if an argument does not match with the expected value
*
*/
class InvalidArgumentException extends LogicException {}
// Do NOT modifiy this doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/class.lengthexception.php )
*
* Exception thrown if a length is invalid
*
*/
class LengthException extends LogicException {}
// Do NOT modifiy this doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/class.outofrangeexception.php )
*
* Exception thrown when a value does not match with a range
*
*/
class OutOfRangeException extends LogicException {}
// Do NOT modifiy this doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/class.runtimeexception.php )
*
* Exception thrown if an error which can only be found on runtime occurs
*
*/
class RuntimeException extends Exception {}
// Do NOT modifiy this doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/class.outofboundsexception.php )
*
* Exception thrown if a value is not a valid key
*
*/
class OutOfBoundsException extends RuntimeException {}
// Do NOT modifiy this doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/class.overflowexception.php )
*
* Exception thrown when you add an element into a full container
*
*/
class OverflowException extends RuntimeException {}
// Do NOT modifiy this doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/class.rangeexception.php )
*
* Exception thrown when an invalid range is given.
*
*/
class RangeException extends RuntimeException {}
// Do NOT modifiy this doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/class.underflowexception.php )
*
* Exception thrown when you try to remove an element of an empty
* container
*
*/
class UnderflowException extends RuntimeException {}
// Do NOT modifiy this doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from
* http://php.net/manual/en/class.unexpectedvalueexception.php )
*
* Exception thrown if a value does not match with a set of values
*
*/
class UnexpectedValueException extends RuntimeException {}
class InvalidOperationException extends RuntimeException {}
// Do NOT modifiy this doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/class.errorexception.php )
*
* An Error Exception.
*
*/
class ErrorException extends Exception {
protected $severity;
public function __construct($message = "", $code = 0, $severity = 0,
$filename = null, $lineno = null) {
parent::__construct($message, $code);
$this->severity = $severity;
if ($filename !== null) {
$this->file = $filename;
}
if ($lineno !== null) {
$this->line = $lineno;
}
}
// Do NOT modifiy this doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/errorexception.getseverity.php )
*
* Returns the severity of the exception.
*
* @return mixed Returns the severity level of the exception.
*/
final public function getSeverity() { return $this->severity; }
}
class DOMException extends Exception {
public function __construct($message, $code) {
parent::__construct($message, $code);
}
}
class PDOException extends Exception {
public function __construct() {
}
}