Back to index

d-push  2.0
Public Member Functions | Public Attributes | Private Attributes
BaseException Class Reference

Defines a base exception class for all custom exceptions, so every exceptions that is thrown/caught by this application should extend this base class and make use of it. More...

List of all members.

Public Member Functions

 __construct ($errorMessage, $code=0, Exception $previous=null, $displayMessage=null)
 Construct the exception.
 __call ($method, array $args)
 Overloading of final methods to get rid of incompatibilities between different PHP versions.
 getFileLine ()
 getDisplayMessage ()
 setDisplayMessage ($message)
 Function sets display message of an exception that will be sent to the client side to show it to user.
 setHandled ()
 Function sets a flag in exception class to indicate that exception is already handled so if it is caught again in the top level of function stack then we have to silently ignore it.
 getBaseFile ()
 _getPrevious ()
 Function will check for PHP version if it is greater than 5.3 then we can use its default implementation otherwise we have to use our own implementation of chanining functionality.
 __toString ()
 String representation of the exception, also handles previous exception.
 getName ()
 Name of the class of exception.

Public Attributes

 $isHandled = false
 Flag to check if exception is already handled or not.
 $displayMessage = null
 The exception message to show at client side.

Private Attributes

 $_previous = null
 Reference of previous exception, only used for PHP < 5.3 can't use $previous here as its a private variable of parent class.
 $baseFile = null
 Base name of the file, so we don't have to use static path of the file.

Detailed Description

Defines a base exception class for all custom exceptions, so every exceptions that is thrown/caught by this application should extend this base class and make use of it.

it removes some peculiarities between different versions of PHP and exception handling.

Some basic function of Exception class getMessage()- message of exception getCode() - code of exception getFile() - source filename getLine() - source line getTrace() - n array of the backtrace() getTraceAsString() - formated string of trace

Definition at line 65 of file class.baseexception.php.


Constructor & Destructor Documentation

BaseException::__construct ( errorMessage,
code = 0,
Exception $  previous = null,
displayMessage = null 
)

Construct the exception.

Parameters:
string$errorMessage
int$code
Exception$previous
string$displayMessage
Returns:
void

Definition at line 97 of file class.baseexception.php.

                                                                                                              {
        // assign display message
        $this->displayMessage = $displayMessage;

        if (version_compare(PHP_VERSION, '5.3.0', '<')) {
            parent::__construct($errorMessage, (int) $code);

            // set previous exception
            if(!is_null($previous)) {
                $this->_previous = $previous;
            }
        } else {
            parent::__construct($errorMessage, (int) $code, $previous);
        }
    }

Member Function Documentation

BaseException::__call ( method,
array $  args 
)

Overloading of final methods to get rid of incompatibilities between different PHP versions.

Parameters:
string$method
array$args
Returns:
mixed

Definition at line 120 of file class.baseexception.php.

    {
        if ('getprevious' == strtolower($method)) {
            return $this->_getPrevious();
        }

        return null;
    }

Here is the call graph for this function:

String representation of the exception, also handles previous exception.

Returns:
string

Definition at line 201 of file class.baseexception.php.

    {
        if (version_compare(PHP_VERSION, '5.3.0', '<')) {
            if (($e = $this->getPrevious()) !== null) {
                return $e->__toString()
                        . "\n\nNext "
                        . parent::__toString();
            }
        }

        return parent::__toString();
    }

Function will check for PHP version if it is greater than 5.3 then we can use its default implementation otherwise we have to use our own implementation of chanining functionality.

Returns:
Exception returns previous exception

Definition at line 187 of file class.baseexception.php.

    {
        if (version_compare(PHP_VERSION, '5.3.0', '<')) {
            return $this->_previous;
        } else {
            return parent::getPrevious();
        }
    }

Here is the caller graph for this function:

Returns:
string returns base path of the file where exception occured.

Definition at line 172 of file class.baseexception.php.

    {
        if(is_null($this->baseFile)) {
            $this->baseFile = basename(parent::getFile());
        }

        return $this->baseFile;
    }

Here is the caller graph for this function:

Returns:
string returns message that should be sent to client to display

Definition at line 140 of file class.baseexception.php.

    {
        if(!is_null($this->displayMessage)) {
            return $this->displayMessage;
        }

        return $this->getMessage();
    }
Returns:
string returns file name and line number combined where exception occured.

Definition at line 132 of file class.baseexception.php.

    {
        return $this->getBaseFile() . ':' . $this->getLine();
    }

Here is the call graph for this function:

Name of the class of exception.

Returns:
string

Definition at line 219 of file class.baseexception.php.

    {
        return get_class($this);
    }

Function sets display message of an exception that will be sent to the client side to show it to user.

Parameters:
string$messagedisplay message.

Definition at line 154 of file class.baseexception.php.

    {
        $this->displayMessage = $message;
    }

Function sets a flag in exception class to indicate that exception is already handled so if it is caught again in the top level of function stack then we have to silently ignore it.

Definition at line 164 of file class.baseexception.php.

    {
        $this->isHandled = true;
    }

Member Data Documentation

BaseException::$_previous = null [private]

Reference of previous exception, only used for PHP < 5.3 can't use $previous here as its a private variable of parent class.

Definition at line 71 of file class.baseexception.php.

BaseException::$baseFile = null [private]

Base name of the file, so we don't have to use static path of the file.

Definition at line 76 of file class.baseexception.php.

The exception message to show at client side.

Definition at line 86 of file class.baseexception.php.

Flag to check if exception is already handled or not.

Definition at line 81 of file class.baseexception.php.


The documentation for this class was generated from the following file: