/src/system/classes/exception.php

https://github.com/kevlund/hiphop-php · PHP · 321 lines · 106 code · 19 blank · 196 comment · 7 complexity · b3f540c6401a370b4bdeb90e01e2cd25 MD5 · raw file

  1. <?php
  2. // Do NOT modifiy this doc comment block generated by idl/sysdoc.php
  3. /**
  4. * ( excerpt from http://php.net/manual/en/class.exception.php )
  5. *
  6. * Exception is the base class for all Exceptions.
  7. *
  8. */
  9. class Exception {
  10. protected $message = ''; // exception message
  11. protected $code = 0; // user defined exception code
  12. protected $previous = null;
  13. protected $file; // source filename of exception
  14. protected $line; // source line of exception
  15. protected $trace; // full stacktrace
  16. /**
  17. * This may not be implemented in __construct(), because a sub-exception
  18. * can implement its own __construct(), losing the stacktrace. Instead,
  19. * the compiler will generate a call to this method inside C++ constructor,
  20. * just to make sure $this->trace is always populated.
  21. */
  22. final function __init__() {
  23. $this->trace = debug_backtrace();
  24. // removing exception constructor stacks to be consistent with PHP
  25. while (!empty($this->trace)) {
  26. $top = $this->trace[0];
  27. if (empty($top['class']) ||
  28. (strcasecmp($top['function'], '__init__') &&
  29. strcasecmp($top['function'], '__construct') &&
  30. strcasecmp($top['function'], $top['class'])) ||
  31. (strcasecmp($top['class'], 'exception') &&
  32. !is_subclass_of($top['class'], 'exception'))) {
  33. break;
  34. }
  35. $frame = array_shift($this->trace);
  36. }
  37. if (isset($frame['file'])) $this->file = $frame['file'];
  38. if (isset($frame['line'])) $this->line = $frame['line'];
  39. }
  40. function __construct($message = '', $code = 0, Exception $previous = null) {
  41. $this->message = $message;
  42. $this->code = $code;
  43. $this->previous = $previous;
  44. }
  45. // message of exception
  46. // Do NOT modifiy this doc comment block generated by idl/sysdoc.php
  47. /**
  48. * ( excerpt from http://php.net/manual/en/exception.getmessage.php )
  49. *
  50. * Returns the Exception message.
  51. *
  52. * @return mixed Returns the Exception message as a string.
  53. */
  54. final function getMessage() {
  55. return $this->message;
  56. }
  57. // message of exception
  58. // Do NOT modifiy this doc comment block generated by idl/sysdoc.php
  59. /**
  60. * ( excerpt from http://php.net/manual/en/exception.getprevious.php )
  61. *
  62. * Returns the previous Exception.
  63. *
  64. * @return mixed Returns the previous Exception if available or NULL otherwise.
  65. */
  66. final function getPrevious() {
  67. return $this->previous;
  68. }
  69. // code of exception
  70. // Do NOT modifiy this doc comment block generated by idl/sysdoc.php
  71. /**
  72. * ( excerpt from http://php.net/manual/en/exception.getcode.php )
  73. *
  74. * Returns the Exception code.
  75. *
  76. * @return mixed Returns the Exception code as a integer.
  77. */
  78. final function getCode() {
  79. return $this->code;
  80. }
  81. // source filename
  82. // Do NOT modifiy this doc comment block generated by idl/sysdoc.php
  83. /**
  84. * ( excerpt from http://php.net/manual/en/exception.getfile.php )
  85. *
  86. * Get the name of the file the exception was thrown from.
  87. *
  88. * @return mixed Returns the filename in which the exception was
  89. * thrown.
  90. */
  91. final function getFile() {
  92. return $this->file;
  93. }
  94. // source line
  95. // Do NOT modifiy this doc comment block generated by idl/sysdoc.php
  96. /**
  97. * ( excerpt from http://php.net/manual/en/exception.getline.php )
  98. *
  99. * Returns line number where the exception was thrown.
  100. *
  101. * @return mixed Returns the line number where the exception was
  102. * thrown.
  103. */
  104. final function getLine() {
  105. return $this->line;
  106. }
  107. // an array of the backtrace()
  108. // Do NOT modifiy this doc comment block generated by idl/sysdoc.php
  109. /**
  110. * ( excerpt from http://php.net/manual/en/exception.gettrace.php )
  111. *
  112. * Returns the Exception stack trace.
  113. *
  114. * @return mixed Returns the Exception stack trace as an array.
  115. */
  116. final function getTrace() {
  117. return $this->trace;
  118. }
  119. // formated string of trace
  120. // Do NOT modifiy this doc comment block generated by idl/sysdoc.php
  121. /**
  122. * ( excerpt from http://php.net/manual/en/exception.gettraceasstring.php )
  123. *
  124. * Returns the Exception stack trace as a string.
  125. *
  126. * @return mixed Returns the Exception stack trace as a string.
  127. */
  128. final function getTraceAsString() {
  129. // works with the new FrameInjection-based stacktrace.
  130. $i = 0;
  131. $s = "";
  132. foreach ($this->getTrace() as $frame) {
  133. if (!is_array($frame)) continue;
  134. $s .= "#$i " .
  135. (isset($frame['file']) ? $frame['file'] : "") . "(" .
  136. (isset($frame['line']) ? $frame['line'] : "") . "): " .
  137. (isset($frame['class']) ? $frame['class'] . $frame['type'] : "") .
  138. $frame['function'] . "()\n";
  139. $i++;
  140. }
  141. $s .= "#$i {main}";
  142. return $s;
  143. }
  144. /* Overrideable */
  145. // formated string for display
  146. function __toString() {
  147. return "exception '" . get_class($this) . "' with message '" .
  148. $this->getMessage() . "' in " . $this->getFile() . ":" .
  149. $this->getLine() . "\nStack trace:\n" . $this->getTraceAsString();
  150. }
  151. }
  152. // Do NOT modifiy this doc comment block generated by idl/sysdoc.php
  153. /**
  154. * ( excerpt from http://php.net/manual/en/class.logicexception.php )
  155. *
  156. * Exception thrown if a logic expression is invalid
  157. *
  158. */
  159. class LogicException extends Exception {}
  160. // Do NOT modifiy this doc comment block generated by idl/sysdoc.php
  161. /**
  162. * ( excerpt from
  163. * http://php.net/manual/en/class.badfunctioncallexception.php )
  164. *
  165. * Exception thrown if a callback refers to an undefined function or if
  166. * some arguments are missing
  167. *
  168. */
  169. class BadFunctionCallException extends LogicException {}
  170. // Do NOT modifiy this doc comment block generated by idl/sysdoc.php
  171. /**
  172. * ( excerpt from http://php.net/manual/en/class.badmethodcallexception.php
  173. * )
  174. *
  175. * Exception thrown if a callback refers to an undefined method or if some
  176. * arguments are missing
  177. *
  178. */
  179. class BadMethodCallException extends BadFunctionCallException {}
  180. // Do NOT modifiy this doc comment block generated by idl/sysdoc.php
  181. /**
  182. * ( excerpt from http://php.net/manual/en/class.domainexception.php )
  183. *
  184. * Exception thrown if a value does not adhere to a defined valid data
  185. * domain
  186. *
  187. */
  188. class DomainException extends LogicException {}
  189. // Do NOT modifiy this doc comment block generated by idl/sysdoc.php
  190. /**
  191. * ( excerpt from
  192. * http://php.net/manual/en/class.invalidargumentexception.php )
  193. *
  194. * Exception thrown if an argument does not match with the expected value
  195. *
  196. */
  197. class InvalidArgumentException extends LogicException {}
  198. // Do NOT modifiy this doc comment block generated by idl/sysdoc.php
  199. /**
  200. * ( excerpt from http://php.net/manual/en/class.lengthexception.php )
  201. *
  202. * Exception thrown if a length is invalid
  203. *
  204. */
  205. class LengthException extends LogicException {}
  206. // Do NOT modifiy this doc comment block generated by idl/sysdoc.php
  207. /**
  208. * ( excerpt from http://php.net/manual/en/class.outofrangeexception.php )
  209. *
  210. * Exception thrown when a value does not match with a range
  211. *
  212. */
  213. class OutOfRangeException extends LogicException {}
  214. // Do NOT modifiy this doc comment block generated by idl/sysdoc.php
  215. /**
  216. * ( excerpt from http://php.net/manual/en/class.runtimeexception.php )
  217. *
  218. * Exception thrown if an error which can only be found on runtime occurs
  219. *
  220. */
  221. class RuntimeException extends Exception {}
  222. // Do NOT modifiy this doc comment block generated by idl/sysdoc.php
  223. /**
  224. * ( excerpt from http://php.net/manual/en/class.outofboundsexception.php )
  225. *
  226. * Exception thrown if a value is not a valid key
  227. *
  228. */
  229. class OutOfBoundsException extends RuntimeException {}
  230. // Do NOT modifiy this doc comment block generated by idl/sysdoc.php
  231. /**
  232. * ( excerpt from http://php.net/manual/en/class.overflowexception.php )
  233. *
  234. * Exception thrown when you add an element into a full container
  235. *
  236. */
  237. class OverflowException extends RuntimeException {}
  238. // Do NOT modifiy this doc comment block generated by idl/sysdoc.php
  239. /**
  240. * ( excerpt from http://php.net/manual/en/class.rangeexception.php )
  241. *
  242. * Exception thrown when an invalid range is given.
  243. *
  244. */
  245. class RangeException extends RuntimeException {}
  246. // Do NOT modifiy this doc comment block generated by idl/sysdoc.php
  247. /**
  248. * ( excerpt from http://php.net/manual/en/class.underflowexception.php )
  249. *
  250. * Exception thrown when you try to remove an element of an empty
  251. * container
  252. *
  253. */
  254. class UnderflowException extends RuntimeException {}
  255. // Do NOT modifiy this doc comment block generated by idl/sysdoc.php
  256. /**
  257. * ( excerpt from
  258. * http://php.net/manual/en/class.unexpectedvalueexception.php )
  259. *
  260. * Exception thrown if a value does not match with a set of values
  261. *
  262. */
  263. class UnexpectedValueException extends RuntimeException {}
  264. // Do NOT modifiy this doc comment block generated by idl/sysdoc.php
  265. /**
  266. * ( excerpt from http://php.net/manual/en/class.errorexception.php )
  267. *
  268. * An Error Exception.
  269. *
  270. */
  271. class ErrorException extends Exception {
  272. protected $severity;
  273. public function __construct($message = "", $code = 0, $severity = 0,
  274. $filename = null, $lineno = null) {
  275. parent::__construct($message, $code);
  276. $this->severity = $severity;
  277. if ($filename !== null) {
  278. $this->file = $filename;
  279. }
  280. if ($lineno !== null) {
  281. $this->line = $lineno;
  282. }
  283. }
  284. // Do NOT modifiy this doc comment block generated by idl/sysdoc.php
  285. /**
  286. * ( excerpt from http://php.net/manual/en/errorexception.getseverity.php )
  287. *
  288. * Returns the severity of the exception.
  289. *
  290. * @return mixed Returns the severity level of the exception.
  291. */
  292. final public function getSeverity() { return $this->severity; }
  293. }
  294. class DOMException extends Exception {
  295. public function __construct($message, $code) {
  296. parent::__construct($message, $code);
  297. }
  298. }
  299. class PDOException extends Exception {
  300. public function __construct() {
  301. }
  302. }