3 * A general abstract exception. You should not throw this even when you
4 * remove the "abstract" key-word. Better you make your own exception and
5 * attach a dedicated message to it.
7 * @author Roland Haeder <webmaster@ship-simu.org>
9 * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software
10 * @license GNU GPL 3.0 or any newer version
11 * @link http://www.ship-simu.org
13 * This program is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation, either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 abstract class FrameworkException extends ReflectionException {
28 * Array for the backtrace
30 private $backTrace = array();
33 * The super constructor for all exceptions
35 * @param $message The non-optional message for the exception
36 * @param $code An optional code for better debugging
39 public function __construct($message, $code = 0) {
41 $this->saveBackTrace();
44 $message = (string) $message;
47 // Make sure everything is assigned properly
48 parent::__construct($message, $code);
52 * Save the current backtrace
56 private final function saveBackTrace () {
58 $this->backTrace = debug_backtrace();
61 $dummy = array_shift($this->backTrace);
64 ksort($this->backTrace);
70 * @return $backTrace The full backtrace in an array
72 public final function getBackTrace () {
73 return $this->backTrace;
77 * Getter for printable backtrace
79 * @return $backTrace Backtrace for web pages
81 public final function getPrintableBackTrace () {
83 $dbgTrace = $this->getBackTrace();
85 // Taken from de.php.net user comments
86 $dbgMsg = "<br />\nDebug backtrace begin:<br />\n";
87 foreach ($dbgTrace as $dbgIndex => $dbgInfo) {
91 // Are there arguments?
92 if ((isset($dbgInfo['args'])) && (is_array($dbgInfo['args'])) && (isset($dbgInfo['args'][0]))) {
93 //* DEBUG: */ echo $dbgIndex.": <pre>".htmlentities(print_r($dbgInfo['args'], true))."</pre>";
95 foreach ($dbgInfo['args'] as $debug) {
96 // Add only non-array elements
97 if (!is_array($debug)) {
102 $info = substr($info, 0, -2);
105 // Prepare argument infos
106 $info = "<em id=\"debug_args\">{$info}</em>";
109 $file = "Unknown file";
110 if (isset($dbgInfo['file'])) {
111 $file = basename($dbgInfo['file']);
115 $line = "Unknown line";
116 if (isset($dbgInfo['line'])) {
117 $line = "line {$dbgInfo['line']}";
121 $dbgMsg .= "\t at <em id=\"debug_id\">".$dbgIndex."</em> <em id=\"debug_file\">".$file."</em> (<em id=\"debug_line\">".$line."</em>) -> ".$dbgInfo['function']."(".$info.")<br />\n";
123 $dbgMsg .= "Debug backtrace end<br />\n";
129 * Returns the name of the thrown exception
131 * @return $toString The name of the thrown exception
133 public function __toString() {
134 return get_class($this);
138 * Getter for hex-decimal code
140 * @param $code Integer code to encode in hex
141 * @return $hexCode The exception code in hex-decimal format
143 public final function getHexCode ($code = null) {
144 // Get the decimal code
145 if (is_null($code)) $code = $this->getCode();
147 // Format it to hex-decimal, 0x as prefix and 3 chars
148 $hexCode = sprintf("0x%03s", dechex($code));