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, 2010 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'] = '0';
48 if (!isset($traceArray['class'])) $traceArray['class'] = 'UnknownObject';
49 if (!isset($traceArray['type'])) $traceArray['type'] = '->';
51 $backTrace .= sprintf("---------- Pos %d: ----------
59 $traceArray['function'],
61 basename($traceArray['file']),
66 // Construct the message
67 $message = sprintf("--------------------------------------------------------------------------------
68 Uncaught Exception : %s
69 --------------------------------------------------------------------------------
74 --------------------------------------------------------------------------------
76 --------------------------------------------------------------------------------
78 --------------------------------------------------------------------------------\n",
79 trim(html_entity_decode(strip_tags($exceptionInstance->__toString()))),
80 trim(html_entity_decode(strip_tags($exceptionInstance->getMessage()))),
81 $exceptionInstance->getHexCode(),
82 $exceptionInstance->getFile(),
83 $exceptionInstance->getLine(),
90 // Invalid exception instance detected! Do *only* throw exceptions that
91 // extends our own exception 'FrameworkException' to get such nice
92 // outputs like above.
93 print("exceptionInstance is invalid! Please inform the core developer team.\n");
98 function __errorHandler ($errno, $errstr, $errfile, $errline, array $errcontext) {
99 // Construct the message
100 $message = sprintf("File: %s, Line: %s, Code: %s, Message: %s",
107 // Throw an exception here
108 throw new FatalErrorException($message, BaseFrameworkSystem::EXCEPTION_FATAL_ERROR);
112 function __assertHandler ($file, $line, $code) {
114 if ($code === '') $code = '<em>Unknown</em>';
117 $message = sprintf("File: %s, Line: %s, Code: %s",
123 // Throw an exception here
124 throw new AssertionException($message, BaseFrameworkSystem::EXCEPTION_ASSERTION_FAILED);
128 //set_error_handler('__errorHandler');
130 // Set the new handler
131 set_exception_handler('hub_exception_handler');
133 // Init assert handling
134 assert_options(ASSERT_ACTIVE, 1);
135 assert_options(ASSERT_WARNING, 0);
136 assert_options(ASSERT_BAIL, 0);
137 assert_options(ASSERT_QUIET_EVAL, 0);
138 assert_options(ASSERT_CALLBACK, '__assertHandler');