5 * @author Sebastian Skejø
8 class AOOSException
extends Exception
10 private $_core = null;
11 private $_name = null;
13 private $_trace = null;
14 private $_ecode = null;
17 * When an AOOSException is constructed it is automatically set in the given $core
18 * @param $core An AOOSCore-object
19 * @param $name The name of the exception to throw
20 * @param $msg A more detailed description of the exception
21 * @param $doTrace If this is true the expection will have a backtrace included in it's output
22 * @param $code Error code. 0 = fatal error, 1 = error, 2 = warning.
24 public function __construct($core, $name, $msg="", $doTrace=true, $code = 1)
32 $this->_trace
= debug_backtrace();
34 if ($code > 2 ||
$code < 0)
36 throw new AOOSException($core, $core->tr("exception_code_error"));
39 $this->_ecode
= $code;
40 $this->core()->setException($this);
44 * Makes sure that it is possible to call
46 * print new AOOSException($core, $name);
49 public function __toString()
55 $str .= "fatal_error";
64 $str .= "</strong>: ".$this->_name
."<br /><div style='font-size: 10pt;'>".$this->_msg
."</div><br /><div style='font-size: 10pt; color: #aaa'>";
65 foreach ($this->_trace
as $row)
67 if (isset($row["class"]))
69 if ($row["class"] == "AOOSException")
73 $str .= "<strong>".$row["class"]."->".$row["function"]."</strong> in ".$row["file"]." on line ".$row["line"]."<br />";
81 * Returns the name of the exception
83 public function getName() { return $this->_name
; }
85 * Returns the description of the exception
87 public function getMsg() { return $this->_msg
; }
89 * Returns the error code of the exception
91 public function getEcode() { return $this->_ecode
; }
93 * Returns the core object
95 public function core() { return $this->_core
; }
99 * A convienience exception class for use when exception should descripe a type error
100 * \internal Use of error in documentation is not good?
102 class AOOSTypeException
extends AOOSException
{
104 * Takes an AOOSCore, $core, an a $type
105 * @param $core An AOOSCore
106 * @param $type Name of the type which caused problems
108 public function __construct($core, $type, $msg) {
109 parent
::__construct($core, "Type Exception", $type.$msg);
113 class AOOSLangException
extends AOOSException
{
114 public function __construct($core, $str) {
115 parent
::__construct($core, "Couldn't find string", "String name: ".$str, true, 2);