3 AOOSCore
::register("AOOSTypeException", "AOOSException.php");
7 * @author Sebastian Skejø
10 class AOOSException
extends Exception
12 private $_core = null;
13 private $_name = null;
15 private $_trace = null;
16 private $_ecode = null;
19 * When an AOOSException is constructed it is automatically set in the given $core
20 * @param $core An AOOSCore-object
21 * @param $name The name of the exception to throw
22 * @param $msg A more detailed description of the exception
23 * @param $doTrace If this is true the expection will have a backtrace included in it's output
24 * @param $code Error code. 0 = fatal error, 1 = error, 2 = warning.
26 public function __construct($core, $name, $msg="", $doTrace=true, $code = 1)
34 $this->_trace
= debug_backtrace();
36 if ($code > 2 ||
$code < 0)
38 throw new AOOSException($core, $core->tr("exception_code_error"));
41 $this->_ecode
= $code;
42 $this->core()->setException($this);
46 * Makes sure that it is possible to call
48 * print new AOOSException($core, $name);
51 public function __toString()
57 $str .= "fatal_error";
66 $str .= "</strong>: ".$this->_name
."<br /><div style='font-size: 10pt;'>".$this->_msg
."</div><br /><div style='font-size: 10pt; color: #aaa'>";
67 foreach ($this->_trace
as $row)
69 if (isset($row["class"]))
71 if ($row["class"] == "AOOSException")
75 $file = in_array("file", array_keys($row)) ?
$row["file"] : "unknown file";
76 $line = in_array("line", array_keys($row)) ?
$row["line"] : "unknown line";
77 $str .= "<strong>".$row["class"]."->".$row["function"]."</strong> in ".$file." on line ".$line."<br />";
85 * Returns the name of the exception
87 public function getName() { return $this->_name
; }
89 * Returns the description of the exception
91 public function getMsg() { return $this->_msg
; }
93 * Returns the error code of the exception
95 public function getEcode() { return $this->_ecode
; }
97 * Returns the core object
99 public function core() { return $this->_core
; }
103 * A convienience exception class for use when exception should descripe a type error
104 * \internal Use of error in documentation is not good?
106 class AOOSTypeException
extends AOOSException
{
108 * Takes an AOOSCore, $core, an a $type
109 * @param $core An AOOSCore
110 * @param $type Name of the type which caused problems
112 public function __construct($core, $type, $msg) {
113 parent
::__construct($core, "Type Exception", $type.$msg);
117 class AOOSLangException
extends AOOSException
{
118 public function __construct($core, $str) {
119 parent
::__construct($core, "Couldn't find string", "String name: ".$str, true, 2);