summaryrefslogtreecommitdiff
path: root/manager/library/exception/exception.Base.php
blob: 7120c379f484f8cf3c70175d64baeb4c46545b17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/**
 * @package SLS
 * @subpackage EXCEPTION
 */

/**
 * extend PHPs standard exception by some details
 *
 * @package SLS
 * @subpackage EXCEPTION
 * @author Markus Warg <mw@it-sls.de>
 * @since 2009-02-23 16:10
 * @version $Id: exception.Base.php 90 2010-03-09 09:48:27Z markus $
 */
class BaseException extends Exception {
    /**
     * additional data / string
     * @var string
     */
    protected $extra = '';

    /**
     * location of thrower
     * @var string
     */
    protected $exception_location = '';

    /**
     * make new object
     *
     * @access public
     * @param string $message
     * @param int $code
     */
    public function __construct($message, $code = 0, $extra = '') {
        $bt = debug_backtrace();

        $remove_exception = 0;
        while( $remove_exception < count($bt) && isset($bt[$remove_exception]['class']) && eregi('exception', $bt[$remove_exception]['class']) ) {
            $remove_exception++;
        }

        if ($remove_exception > 0)
            $remove_exception--;

        if ($remove_exception < count($bt)) {
            $this->exception_location = $bt[$remove_exception]['file'].':'.$bt[$remove_exception]['line'];
        }

           $this->extra = $extra;

        parent::__construct($message,$code);
    }

    /**
     * Make a string out of this exception
     *
     * @access public
     * @return string
     */
    public function __toString() {
        $out = __CLASS__ . '['.$this->code.']:';

        if ($this->exception_location != '')
            $out.= $this->exception_location;
        $out .= ':';

        $out .= " {$this->message}";

        if (isset($this->extra) && strlen($this->extra) > 0)
            $out .= " ({$this->extra})\n";

        return $out;
    }

    /**
     * get the extra info string
     *
     * @access public
     * @return string
     */
    public function getExtraInfo() {
        return $this->extra;
    }

    /**
     * get the exception location string
     *
     * @access public
     * @return string
     */
    public function getExceptionLocation() {
        return $this->exception_location;
    }

}