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, this is free software
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 $traceArray = $trace[$idx];
37 // Convert arguments type into human-readable
38 $args = $traceArray['args'];
40 foreach ($args as $arg) {
41 $argsString .= ", ".gettype($arg);
43 $argsString = substr($argsString, 2);
45 $backTrace .= sprintf("---------- Pos %d: ----------
53 $traceArray['function'],
55 basename($traceArray['file']),
60 // Construct the message
61 $message = sprintf("--------------------------------------------------------------------------------
62 Uncaught Exception : %s
63 --------------------------------------------------------------------------------
68 --------------------------------------------------------------------------------
70 --------------------------------------------------------------------------------
72 --------------------------------------------------------------------------------\n",
73 trim(html_entity_decode(strip_tags($exceptionInstance->__toString()))),
74 trim(html_entity_decode(strip_tags($exceptionInstance->getMessage()))),
75 $exceptionInstance->getHexCode(),
76 $exceptionInstance->getFile(),
77 $exceptionInstance->getLine(),
86 // Set the new handler
87 set_exception_handler('hub_exception_handler');