Adding the start of a simple module - SimplePortfolio
[AOOS.git] / AOOSException.php
blob0e7950b68e1a956e502fea1e9b5cf86a7ed8e986
1 <?php
3 /**
4 * AOOSException
5 * @author Sebastian Skejø
6 */
8 class AOOSException extends Exception
10 private $_core = null;
11 private $_name = null;
12 private $_msg = null;
13 private $_trace = null;
14 private $_ecode = null;
16 public function __construct($core, $name, $msg="", $doTrace=true, $code = 0)
18 $this->core() = $core;
19 $this->_name = $name;
20 $this->_msg = $msg;
21 if ($doTrace)
23 $this->_trace = debug_backtrace();
25 if ($code > 2 || $code < 0)
27 throw new AOOSException($core, $core->tr("exception_code_error"));
28 return false;
30 $this->_ecode = $code;
31 $this->core()->setException($this);
34 public function __toString()
36 $str = "<strong>";
37 switch($this->_ecode)
39 case(0):
40 $str .= "fatal_error";
41 break;
42 case(1):
43 $str .= "error";
44 break;
45 case(2):
46 $str .= "warning";
47 break;
49 $str .= "</strong>: ".$this->_name."<br /><div style='font-size: 10pt;'>".$this->_msg."</div><br /><div style='font-size: 10pt; color: #aaa'>";
50 foreach ($this->_trace as $row)
52 if (isset($row["class"]))
54 if ($row["class"] == "AOOSException")
56 continue;
58 $str .= "<strong>".$row["class"]."->".$row["function"]."</strong> in ".$row["file"]." on line ".$row["line"]."<br />";
61 $str .= "</div>";
62 return $str;
65 public function getName() { return $this->_name; }
66 public function getMsg() { return $this->_msg; }
67 public function getEcode() { return $this->_ecode; }