3 * An include file for setting up the exception handler of the hub
6 * @author Roland Haeder <webmaster@ship-simu.org>
8 * @copyright Copyright (c) 2007 - 2008 Roland Haeder, 2009 Hub Developer Team
9 * @license GNU GPL 3.0 or any newer version
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 // The hub's own exception handler
26 function hub_exception_handler ($exceptionInstance) {
27 // Is it an object and a valid instance?
28 if ((is_object($exceptionInstance)) && ($exceptionInstance instanceof FrameworkException)) {
29 // Get the regular trace
30 $trace = $exceptionInstance->getTrace();
34 for ($idx = 0; $idx < 3; $idx++) {
35 // Copy array for argument analysis and init variable
36 $traceArray = $trace[$idx];
39 // Convert arguments type into human-readable
40 foreach ($traceArray['args'] as $arg) {
41 $argsString .= ", " . gettype($arg);
43 $argsString = substr($argsString, 2);
45 // Set missing file/line
46 if (!isset($traceArray['file'])) $traceArray['file'] = 'unknown';
47 if (!isset($traceArray['line'])) $traceArray['line'] = 'unknown';
49 $backTrace .= sprintf("---------- Pos %d: ----------
57 $traceArray['function'],
59 basename($traceArray['file']),
64 // Construct the message
65 $message = sprintf("--------------------------------------------------------------------------------
66 Uncaught Exception : %s
67 --------------------------------------------------------------------------------
72 --------------------------------------------------------------------------------
74 --------------------------------------------------------------------------------
76 --------------------------------------------------------------------------------\n",
77 trim(html_entity_decode(strip_tags($exceptionInstance->__toString()))),
78 trim(html_entity_decode(strip_tags($exceptionInstance->getMessage()))),
79 $exceptionInstance->getHexCode(),
80 $exceptionInstance->getFile(),
81 $exceptionInstance->getLine(),
88 // Invalid exception instance detected! Do *only* throw exceptions that
89 // extends our own exception 'FrameworkException' to get such nice
90 // outputs like above.
91 print("exceptionInstance is invalid! Please inform the core developer team.\n");
95 // Set the new handler
96 set_exception_handler('hub_exception_handler');