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)) {
31 // Get all call levels from backtrace
32 foreach ($exceptionInstance->getTrace() as $idx => $traceArray) {
33 // Init argument string
36 // Convert arguments type into human-readable
37 foreach ($traceArray['args'] as $arg) {
38 $argsString .= ', ' . gettype($arg);
40 $argsString = substr($argsString, 2);
42 // Set missing file/line
43 if (!isset($traceArray['file'])) $traceArray['file'] = 'unknown';
44 if (!isset($traceArray['line'])) $traceArray['line'] = '0';
45 if (!isset($traceArray['class'])) $traceArray['class'] = 'UnknownObject';
46 if (!isset($traceArray['type'])) $traceArray['type'] = '->';
48 $backTrace .= sprintf("---------- Pos %d: ----------
56 $traceArray['function'],
58 basename($traceArray['file']),
63 // Construct the message
64 $message = sprintf("--------------------------------------------------------------------------------
65 Uncaught Exception : %s
66 --------------------------------------------------------------------------------
71 --------------------------------------------------------------------------------
73 --------------------------------------------------------------------------------
75 --------------------------------------------------------------------------------\n",
76 trim(html_entity_decode(strip_tags($exceptionInstance->__toString()))),
77 trim(html_entity_decode(strip_tags($exceptionInstance->getMessage()))),
78 $exceptionInstance->getHexCode(),
79 $exceptionInstance->getFile(),
80 $exceptionInstance->getLine(),
87 // Invalid exception instance detected! Do *only* throw exceptions that
88 // extends our own exception 'FrameworkException' to get such nice
89 // outputs like above.
90 print("exceptionInstance is invalid! Please inform the core developer team.\n");
95 function __errorHandler ($errno, $errstr, $errfile, $errline, array $errcontext) {
96 // Construct the message
97 $message = sprintf("File: %s, Line: %s, Code: %s, Message: %s",
104 // Throw an exception here
105 throw new FatalErrorException($message, BaseFrameworkSystem::EXCEPTION_FATAL_ERROR);
109 function __assertHandler ($file, $line, $code) {
112 $code = '<em>Unknown</em>';
116 $message = sprintf("File: %s, Line: %s, Code: %s",
122 // Throw an exception here
123 throw new AssertionException($message, BaseFrameworkSystem::EXCEPTION_ASSERTION_FAILED);
127 //set_error_handler('__errorHandler');
129 // Set the new handler
130 set_exception_handler('hub_exception_handler');
132 // Init assert handling
133 assert_options(ASSERT_ACTIVE, true);
134 assert_options(ASSERT_WARNING, false);
135 assert_options(ASSERT_BAIL, false);
136 assert_options(ASSERT_QUIET_EVAL, false);
137 assert_options(ASSERT_CALLBACK, '__assertHandler');