3 * An include file for setting up the exception handler of the hub
5 * @author Roland Haeder <webmaster@ship-simu.org>
7 * @copyright Copyright (c) 2007 - 2008 Roland Haeder, 2009 - 2012 Hub Developer Team
8 * @license GNU GPL 3.0 or any newer version
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 // The node's own exception handler
25 function hub_exception_handler ($exceptionInstance) {
26 // Is it an object and a valid instance?
27 if ((is_object($exceptionInstance)) && ($exceptionInstance instanceof FrameworkException)) {
28 // Get the regular trace
29 $trace = $exceptionInstance->getTrace();
33 for ($idx = 0; $idx < 3; $idx++) {
34 // Copy array for argument analysis and init variable
35 $traceArray = $trace[$idx];
38 // Convert arguments type into human-readable
39 foreach ($traceArray['args'] as $arg) {
40 $argsString .= ', ' . gettype($arg);
42 $argsString = substr($argsString, 2);
44 // Set missing file/line
45 if (!isset($traceArray['file'])) $traceArray['file'] = 'unknown';
46 if (!isset($traceArray['line'])) $traceArray['line'] = '0';
47 if (!isset($traceArray['class'])) $traceArray['class'] = 'UnknownObject';
48 if (!isset($traceArray['type'])) $traceArray['type'] = '->';
50 $backTrace .= sprintf("---------- Pos %d: ----------
58 $traceArray['function'],
60 basename($traceArray['file']),
65 // Construct the message
66 $message = sprintf("--------------------------------------------------------------------------------
67 Uncaught Exception : %s
68 --------------------------------------------------------------------------------
73 --------------------------------------------------------------------------------
75 --------------------------------------------------------------------------------
77 --------------------------------------------------------------------------------\n",
78 trim(html_entity_decode(strip_tags($exceptionInstance->__toString()))),
79 trim(html_entity_decode(strip_tags($exceptionInstance->getMessage()))),
80 $exceptionInstance->getHexCode(),
81 $exceptionInstance->getFile(),
82 $exceptionInstance->getLine(),
89 // Invalid exception instance detected! Do *only* throw exceptions that
90 // extends our own exception 'FrameworkException' to get such nice
91 // outputs like above.
92 print("exceptionInstance is invalid! Please inform the core developer team.\n");
97 function __errorHandler ($errno, $errstr, $errfile, $errline, array $errcontext) {
98 // Construct the message
99 $message = sprintf("File: %s, Line: %s, Code: %s, Message: %s",
106 // Throw an exception here
107 throw new FatalErrorException($message, BaseFrameworkSystem::EXCEPTION_FATAL_ERROR);
111 function __assertHandler ($file, $line, $code) {
114 $code = '<em>Unknown</em>';
118 $message = sprintf("File: %s, Line: %s, Code: %s",
124 // Throw an exception here
125 throw new AssertionException($message, BaseFrameworkSystem::EXCEPTION_ASSERTION_FAILED);
129 //set_error_handler('__errorHandler');
131 // Set the new handler
132 set_exception_handler('hub_exception_handler');
134 // Init assert handling
135 assert_options(ASSERT_ACTIVE, true);
136 assert_options(ASSERT_WARNING, false);
137 assert_options(ASSERT_BAIL, false);
138 assert_options(ASSERT_QUIET_EVAL, false);
139 assert_options(ASSERT_CALLBACK, '__assertHandler');