]> git.mxchange.org Git - shipsimu.git/blob - application/ship-simu/exceptions.php
Simple exception handler and error handler added, profile update added with stubs
[shipsimu.git] / application / ship-simu / exceptions.php
1 <?php
2 /**
3  * The exception handler for this application
4  *
5  * @author              Roland Haeder <webmaster@ship-simu.org>
6  * @version             0.0.0
7  * @copyright   Copyright(c) 2007, 2008 Roland Haeder, this is free software
8  * @license             GNU GPL 3.0 or any newer version
9  * @link                http://www.ship-simu.org
10  *
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.
15  *
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.
20  *
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/>.
23  */
24
25 // Our own exception handler
26 function __exceptionHandler (FrameworkException $e) {
27         // Call the app_die() method
28         ApplicationEntryPoint::app_die(sprintf("[Main:] The application <strong>%s</strong> (<strong>%s</strong>) has been terminated due to a thrown exception: <strong>%s: <span id=\"debug_exception\">%s</em></strong>. Backtrace: <div id=\"debug_backtrace\">%s</div>",
29                 ApplicationHelper::getInstance()->getAppName(),
30                 ApplicationHelper::getInstance()->getAppShortName(),
31                 $e->__toString(),
32                 $e->getMessage(),
33                 $e->getPrintableBackTrace()
34         ));
35 }
36
37 // Set the new handler
38 set_exception_handler('__exceptionHandler');
39
40 // Error handler
41 function __errorHandler ($errno, $errstr, $errfile, $errline, array $errcontext) {
42         // Construct the message
43         $message = sprintf("File: <span id=\"debug_file\">%s</span>, Line: <span id=\"debug_line\">%s</span>, Code: <span id=\"debug_code\">%s</span>, Message: <span id=\"debug_message\">%s</span>",
44                 basename($errfile),
45                 $errline,
46                 $errno,
47                 $errstr
48         );
49
50         // Throw an exception here
51         throw new FatalErrorException($message, BaseFrameworkSystem::EXCEPTION_FATAL_ERROR);
52 }
53
54 // Set error handler
55 set_error_handler('__errorHandler');
56
57 // [EOF]
58 ?>