Source for file Exception.class.php
Documentation is available at Exception.class.php
* Gumbo Library Framework
* This library is being released under the terms of the New BSD License. A
* copy of the license is packaged with the software (LICENSE.txt). If no
* copy is found, a copy of the license template can be found at:
* http://www.opensource.org/licenses/bsd-license.php
* @copyright Copyright (c) 2007, iBayou, Michael Luster
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @author Michael Luster <mluster79@yahoo.com>
* @link http://sourceforge.net/projects/phpgumbo
* A Gumbo Exception is an extension to the PHP5 Exception class. The extra
* methods defined allows the programmer to provide special information to
* the Exception. All Exceptions are defaulted to the ERROR_DEBUG level. This
* can be defined by the 'code' argument.
* The function setting will accept a function name or a class method. This
* should be set using either __FUNCTION__ or __METHOD__. This element does not
* need to be set, but useful if thrown inside a function or method.
* The Exception contains static methods that are involved with the __toString
* method. The values determine which pieces are displayed. The __toString
* method provides an HTML formatted message, with class and id attributes to
* Exceptions should be thrown using try...catch blocks. Once thrown, the file
* and line number will automatically be set.
* throw new Gumbo_Exception ("<error message>");
* } catch (Gumbo_Exception $e) {
* $e->setFunction (__METHOD__);
* Exceptions could be created by creating a new Exception object directly. The
* file and line number may not be set, but the Exception object will still contain
* $e = new Gumbo_Exception ("<error message>", ERROR_LEVEL, __FILE__, __LINE__, __METHOD__);
* @copyright Copyright (c) 2007, iBayou, Michael Luster
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @author Michael Luster <mluster79@yahoo.com>
* @link http://sourceforge.net/projects/phpgumbo
gumbo_load ("Interface_Exception");
/** @var string $_function class method file name */
/** @var bool $_display_title displays the Error title bar */
private static $_display_title =
true;
/** @var bool $_display_function displays the function in the error message */
private static $_display_function =
true;
/** @var bool $_display_file displays the file in the error message */
private static $_display_file =
true;
/** @var bool $_display_trace displays the error trace in message */
private static $_display_trace =
true;
* @param string $mess Error message
* @param int $code Error level code
* @param string $file file name
* @param int $line line number
* @param string $func function/method name
public function __construct ($mess, $code=
0, $file=
null, $line=
0, $func=
null) {
parent::__construct ($mess, $code);
* Displays the error title
* Displays the function information
if (!is_bool ($val)) { return; }
* Displays the file information
if (!is_bool ($val)) { return; }
* Displays the error trace information
if (!is_bool ($val)) { return; }
if (!is_string ($mess)) { return; }
* Sets the error level code
if (!is_int ($code)) { return; }
if ($code <=
0) { return; }
* Sets the file name where error occured
* Sets the line number where error occured
if (!is_int ($line)) { return; }
if ($line <=
0) { return; }
* Sets the function or class method
* @param string $func function/method name
* Returns the function / class method name
* Returns the Object in string format
* The following CSS style rules apply to an Error message
* - div.error h3 :: Error Title
* - div.error p :: Error Message
* - div.error p.details :: Error Class::Function and File Name
* - div.error ul :: Error Trace details
* - div.error ul li :: Trace Line Item
* - - *.file :: file name
* - - *.line :: file line number
* - - *.cls :: class name
* - - *.function :: function/method name
* - - *.typeArray :: parameter type Array
* - - *.typeClass :: parameter type Class
* - - *.typeNull :: parameter type null
* - - *.typeResource :: parameter type Resource
* - - *.typeBoolean :: parameter type Boolean
* - - *.typeNumber :: parameter type numeric
* - - *.typeString :: parameter type String
switch ($this->getCode ()) {
case ERROR_ERROR :
$level =
"error"; $color =
"urgent"; break;
case ERROR_ALERT :
$level =
"alert"; $color =
"urgent"; break;
default :
$level =
"unknown";
$txt =
"<div class=\"error\">\n";
$txt .=
"\t<h3 class=\"" .
$color .
"\">" .
ucwords ($level) .
"</h3>\n";
$txt .=
"\t<p>" .
$this->getMessage () .
"</p>\n";
if (Gumbo_Exception::$_display_function ||
Gumbo_Exception::$_display_file) {
$txt .=
"\t<p class=\"details\">";
if (Gumbo_Exception::$_display_function) {
$txt .=
"<code>" .
$this->getFunction () .
" ()</code><br />";
if (Gumbo_Exception::$_display_file) {
$txt .=
$this->getFile () .
" [" .
$this->getLine () .
"]";
// retrieving Trace information
if (Gumbo_Exception::$_display_trace) {
$trace =
$this->getTrace ();
for ($x =
$num;$x >=
0;$x--
) {
if (count ($trace [$x]) ==
0) { continue; }
$txt .=
"<em class=\"file\">" .
$trace [$x]['file'] .
"</em> [<em class=\"line\">" .
$trace [$x]['line'] .
"</em>] ";
if ($trace [$x]['function']) { $txt .=
"--- "; }
if ($trace [$x]['class']) { $txt .=
"<em class=\"cls\">" .
$trace [$x]['class'] .
"</em>" .
$trace [$x]['type']; }
if ($trace [$x]['function']) {
$txt .=
"<em class=\"function\">" .
$trace [$x]['function'] .
"</em> ( ";
$num =
count ($trace [$x]['args']);
foreach ($trace [$x]['args'] as $key=>
$val) {
$tmp .=
"<em class=\"typeArray\">Array</em>";
$tmp .=
"<em class=\"typeClass\">" .
get_class ($val) .
"</em>";
$tmp .=
"<em class=\"typeNull\">null</em>";
$tmp .=
"<em class=\"typeResource\">Resource</em>";
$tmp .=
"<em class=\"typeBoolean\">";
$tmp .=
"<em class=\"typeNumber\"" .
$val .
"</em>";
$tmp .=
"<em class=\"typeString\">\"" .
$val .
"\"</em>";