b7db9a34d639f6d45751144c9f0821de1391cd30
[mailer.git] / inc / classes / exceptions / class_FrameworkException.php
1 <?php
2 /**
3  * A general abstract exception. You should not throw this even when you
4  * remove the "abstract" key-word. Better you make your own exception and
5  * attach a dedicated message to it.
6  *
7  * @author              Roland Haeder <webmaster@ship-simu.org>
8  * @version             0.0.0
9  * @copyright   Copyright(c) 2007, 2008 Roland Haeder, this is free software
10  * @license             GNU GPL 3.0 or any newer version
11  * @link                http://www.ship-simu.org
12  *
13  * This program is free software: you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation, either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
25  */
26 abstract class FrameworkException extends ReflectionException {
27         /**
28          * Array for the backtrace
29          */
30         private $backTrace = array();
31
32         /**
33          * The super constructor for all exceptions
34          *
35          * @param               $message                The non-optional message for the exception
36          * @param               $code           An optional code for better debugging
37          * @return      void
38          */
39         public function __construct($message, $code = 0) {
40                 // Extract backtrace
41                 $this->saveBackTrace();
42
43                 // Cast all data
44                 $message = (string) $message;
45                 $code    = (int)    $code;
46
47                 // make sure everything is assigned properly
48                 parent::__construct($message, $code);
49         }
50
51         /**
52          * Save the current backtrace
53          *
54          * @return      void
55          */
56         private final function saveBackTrace () {
57                 $this->backTrace = debug_backtrace();
58         }
59
60         /**
61          * Get saved backtrace
62          *
63          * @return      $backTrace      The full backtrace in an array
64          */
65         public final function getBackTrace () {
66                 return $this->backTrace;
67         }
68
69         /**
70          * Returns the name of the thrown exception
71          *
72          * @return      $toString               The name of the thrown exception
73          */
74         public function __toString() {
75                 return get_class($this);
76         }
77
78         /**
79          * Getter for hex-decimal code
80          *
81          * @return      $hexCode        The exception code in hex-decimal format
82          */
83         public final function getHexCode () {
84                 // Get the decimal code
85                 $code = $this->getCode();
86
87                 // Format it to hex-decimal, 0x as prefix and 3 chars
88                 $hexCode = sprintf("0x%03s", dechex($code));
89
90                 // Return it
91                 return $hexCode;
92         }
93 }
94
95 // [EOF]
96 ?>