]> git.mxchange.org Git - shipsimu.git/blob - application/selector/exceptions.php
Continued:
[shipsimu.git] / application / selector / exceptions.php
1 <?php
2 /**
3  * The exception handler for this application
4  *
5  * @author              Roland Haeder <webmaster@shipsimu.org>
6  * @version             0.0.0
7  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 Ship-Simu Developer Team
8  * @license             GNU GPL 3.0 or any newer version
9  * @link                http://www.shipsimu.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_exit() method
28         ApplicationEntryPoint::app_exit(sprintf('[Main:] The application <span class="app_name">%s</span> (<span class="app_short_name">%s</span>) has terminated due to an uncaught exception: <span class="exception_name">%s</span> <span class="exception_number">[%s]</span>: <span class="debug_exception">%s</span> Backtrace: <div class="debug_backtrace">%s</div>',
29                 ApplicationHelper::getSelfInstance()->getAppName(),
30                 ApplicationHelper::getSelfInstance()->getAppShortName(),
31                 $e->__toString(),
32                 $e->getHexCode(),
33                 $e->getMessage(),
34                 $e->getPrintableBackTrace()
35         ),
36                 $e->getHexCode(),
37                 $e->getExtraData()
38         );
39 } // END - function
40
41 // Set the new handler
42 set_exception_handler('__exceptionHandler');
43
44 // Error handler
45 function __errorHandler ($errno, $errstr, $errfile, $errline, array $errcontext) {
46         // Construct the message
47         $message = sprintf('File: <span class="debug_file">%s</span>, Line: <span class="debug_line">%s</span>, Code: <span class="debug_code">%s</span>, Message: <span class="debug_message">%s</span>',
48                 basename($errfile),
49                 $errline,
50                 $errno,
51                 $errstr
52         );
53
54         // Throw an exception here
55         throw new FatalErrorException($message, BaseFrameworkSystem::EXCEPTION_FATAL_ERROR);
56 } // END - function
57
58 // Set error handler
59 set_error_handler('__errorHandler');
60
61 // Assertion handler
62 function __assertHandler ($file, $line, $code) {
63         // Empty code?
64         if (empty($code)) {
65                 $code = '<em>Unknown</em>';
66         }
67
68         // Create message
69         $message = sprintf('File: <span class="debug_file">%s</span>, Line: <span class="debug_line">%s</span>, Code: <span class="debug_code">%s</span>',
70                 basename($file),
71                 $line,
72                 $code
73         );
74
75         // Throw an exception here
76         throw new AssertionException($message, BaseFrameworkSystem::EXCEPTION_ASSERTION_FAILED);
77 } // END - function
78
79 // Init assert handling
80 assert_options(ASSERT_ACTIVE,     1);
81 assert_options(ASSERT_WARNING,    0);
82 assert_options(ASSERT_BAIL,       0);
83 assert_options(ASSERT_QUIET_EVAL, 0);
84 assert_options(ASSERT_CALLBACK,   '__assertHandler');