2 namespace __SystemLib
{
3 // This doc comment block generated by idl/sysdoc.php
5 * ( excerpt from http://php.net/manual/en/class.exception.php )
7 * Exception is the base class for all Exceptions.
11 require implements \Throwable
;
14 * throwable_init() and createAndConstructThrowable() depend on the order
15 * of properties below:
17 protected string $message = ''; // exception message
18 private string $string = ''; // php5 has this, we don't use it
19 protected int $code = 0; // user defined exception code
20 protected string $file; // source filename of exception
21 protected int $line; // source line of exception
22 private $trace = varray
[]; // full stacktrace
23 private ?\Exception
$previous = null;
24 protected $userMetadata = null;
26 // This doc comment block generated by idl/sysdoc.php
28 * ( excerpt from http://php.net/manual/en/exception.getmessage.php )
30 * Returns the Exception message.
32 * @return mixed Returns the Exception message as a string.
34 <<__Rx
, __OnlyRxIfImpl(\HH\Rx\Exception
::class), __MaybeMutable
>>
35 public function getMessage() {
36 return $this->message
;
39 // This doc comment block generated by idl/sysdoc.php
41 * ( excerpt from http://php.net/manual/en/exception.getprevious.php )
43 * Returns previous Exception (the third parameter of
44 * Exception::__construct()).
46 * @return mixed Returns the previous Exception if available or NULL
49 final public function getPrevious() {
50 return $this->previous
;
53 final public function setPrevious(\Throwable
$previous) {
54 $this->previous
= $previous;
57 final public function setPreviousChain(\Throwable
$previous) {
60 $cycle[\
spl_object_hash($cur)] = true;
61 $next = $cur->getPrevious();
62 while ($next is \Throwable
&&
63 !\array_key_exists
(\
spl_object_hash($next), $cycle)) {
64 $cycle[\
spl_object_hash($next)] = true;
66 $next = $cur->getPrevious();
68 $cur->setPrevious($previous);
71 // This doc comment block generated by idl/sysdoc.php
73 * ( excerpt from http://php.net/manual/en/exception.getcode.php )
75 * Returns the Exception code.
77 * @return mixed Returns the exception code as integer in Exception
78 * but possibly as other type in Exception descendants
79 * (for example as string in PDOException).
81 <<__Rx
, __OnlyRxIfImpl(\HH\Rx\Exception
::class), __MaybeMutable
>>
82 public function getCode() {
86 // This doc comment block generated by idl/sysdoc.php
88 * ( excerpt from http://php.net/manual/en/exception.getfile.php )
90 * Get the name of the file the exception was created.
92 * @return mixed Returns the filename in which the exception was
95 <<__Rx
, __MaybeMutable
>>
96 final public function getFile() {
100 // This doc comment block generated by idl/sysdoc.php
102 * ( excerpt from http://php.net/manual/en/exception.getline.php )
104 * Get line number where the exception was created.
106 * @return mixed Returns the line number where the exception was
109 <<__Rx
, __MaybeMutable
>>
110 final public function getLine() {
114 // This doc comment block generated by idl/sysdoc.php
116 * ( excerpt from http://php.net/manual/en/exception.gettrace.php )
118 * Returns the Exception stack trace.
120 * @return mixed Returns the Exception stack trace as an array.
122 final public function getTrace() {
123 if (\
is_resource($this->trace
)) {
124 $this->trace
= \__SystemLib\
extract_trace($this->trace
);
130 * Modifies the exception's trace by prepending the provided trace.
131 * Does not modify file, line, etc.
133 final protected function __prependTrace(\HH\Container
$trace): void
{
134 $this->trace
= varray(
136 \array_values
($trace),
142 // This doc comment block generated by idl/sysdoc.php
144 * ( excerpt from http://php.net/manual/en/exception.gettraceasstring.php )
146 * Returns the Exception stack trace as a string.
148 * @return mixed Returns the Exception stack trace as a string.
150 final public function getTraceAsString() {
153 foreach ($this->getTrace() as $frame) {
154 if (!\HH\
is_any_array($frame)) continue;
156 ($frame['file'] ??
"") . "(" .
157 ($frame['line'] ??
"") . "): " .
158 (isset($frame['class'])
159 ?
$frame['class'] . ($frame['type'] ??
"")
162 ($frame['function'] ??
"<unknown>") . "()\n";
170 * Set metadata property on this exception
172 final public function setUserMetadata(mixed $user_metadata): void
{
173 $this->userMetadata
= $user_metadata;
177 * Get metadata from this exception
179 final public function getUserMetadata(): mixed {
180 return $this->userMetadata
;
183 public function __toString() {
184 return $this->toString();
188 // formated string for display
189 // This doc comment block generated by idl/sysdoc.php
191 * ( excerpt from http://php.net/manual/en/exception.tostring.php )
193 * Returns the string representation of the exception.
195 * @return mixed Returns the string representation of the exception.
197 public function toString() {
201 while ($ex != null && !\array_key_exists
(\
spl_object_hash($ex), $lst)) {
202 $lst[\
spl_object_hash($ex)] = $ex;
203 $ex = $ex->getPrevious();
205 $lst = \array_reverse
($lst);
207 foreach ($lst as $ex) {
211 $cls = \
get_class($ex);
212 if (\
substr($cls, 0, \
strlen("__SystemLib\\")) === "__SystemLib\\") {
213 $cls = \
substr($cls, \
strlen("__SystemLib\\"));
215 $res .= $ex is \Error
216 ?
$cls . ": " . $ex->getMessage()
217 : "exception '" . $cls . "' with message '" . $ex->getMessage() . "'";
218 $res .= " in " . $ex->getFile() . ":" .
219 $ex->getLine() . "\nStack trace:\n" . $ex->getTraceAsString();
225 final private function __clone() {
226 \trigger_error
("Trying to clone an uncloneable object of class " .
227 \
get_class($this), \E_USER_ERROR
);