Arquivos
hhvm/hphp/system/classes/exception.php
T
Paul Tarjan ed171866b7 update docs
2013-05-24 10:10:58 -07:00

410 linhas
12 KiB
PHP

<?php
// 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;
}
// This doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/exception.construct.php )
*
* Constructs the Exception.
*
* @message mixed The Exception message to throw.
* @code mixed The Exception code.
* @previous mixed The previous exception used for the exception
* chaining.
*/
function __construct($message = '', $code = 0, Exception $previous = null) {
$this->message = $message;
$this->code = $code;
$this->previous = $previous;
}
// 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;
}
// This doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/exception.getprevious.php )
*
* Returns previous Exception (the third parameter of
* Exception::__construct()).
*
* @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);
}
// 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 integer in Exception
* but possibly as other type in Exception descendants
* (for example as string in PDOException).
*/
function getCode() {
return $this->code;
}
// 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 created.
*
* @return mixed Returns the filename in which the exception was
* created.
*/
final function getFile() {
return $this->file;
}
// This doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/exception.getline.php )
*
* Get line number where the exception was created.
*
* @return mixed Returns the line number where the exception was
* created.
*/
final function getLine() {
return $this->line;
}
// 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;
}
// 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
// This doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/exception.tostring.php )
*
* Returns the string representation of the exception.
*
* @return mixed Returns the string representation of the exception.
*/
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;
}
}
// This doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/class.logicexception.php )
*
* Exception that represents error in the program logic. This kind of
* exceptions should directly lead to a fix in your code.
*
*/
class LogicException extends Exception {}
// 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 {}
// 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 {}
// 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 {}
// 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 {}
// 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 {}
// This doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/class.outofrangeexception.php )
*
* Exception thrown when an illegal index was requested. This represents
* errors that should be detected at compile time.
*
*/
class OutOfRangeException extends LogicException {}
// 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 {}
// 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. This represents errors
* that cannot be detected at compile time.
*
*/
class OutOfBoundsException extends RuntimeException {}
// This doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/class.overflowexception.php )
*
* Exception thrown when adding an element to a full container.
*
*/
class OverflowException extends RuntimeException {}
// This doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/class.rangeexception.php )
*
* Exception thrown to indicate range errors during program execution.
* Normally this means there was an arithmetic error other than
* under/overflow. This is the runtime version of DomainException.
*
*/
class RangeException extends RuntimeException {}
// This doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/class.underflowexception.php )
*
* Exception thrown when performing an invalid operation on an empty
* container, such as removing an element.
*
*/
class UnderflowException extends RuntimeException {}
// 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.
* Typically this happens when a function calls another function and
* expects the return value to be of a certain type or value not including
* arithmetic or buffer related errors.
*
*/
class UnexpectedValueException extends RuntimeException {}
class InvalidOperationException extends RuntimeException {}
// 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;
// This doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/errorexception.construct.php )
*
* Constructs the Exception.
*
* @message mixed The Exception message to throw.
* @code mixed The Exception code.
* @severity mixed The severity level of the exception.
* @filename mixed The filename where the exception is thrown.
* @lineno mixed The line number where the exception is thrown.
*/
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;
}
}
// 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; }
}
// This doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/class.domexception.php )
*
* DOM operations raise exceptions under particular circumstances, i.e.,
* when an operation is impossible to perform for logical reasons.
*
* See also Exceptions.
*
*/
class DOMException extends Exception {
public function __construct($message, $code) {
parent::__construct($message, $code);
}
}
// This doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/class.pdoexception.php )
*
* Represents an error raised by PDO. You should not throw a PDOException
* from your own code. See Exceptions for more information about Exceptions
* in PHP.
*
*/
class PDOException extends Exception {
public function __construct() {
}
}