WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : ExceptionError Package : Transform all the PHP errors into catchable exceptions.
Categories : PHP, PHP Classes, Errors and Logging Click here to Update Your Picture
Johan Barbier
Date : Oct 20th 2007
Grade : 5 of 5 (graded 1 times)
Viewed : 1066
File : 4703.zip
Images : No Images for this code example.
Search : More code by Johan Barbier
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

It enables you to do that :



<?php
try {
    echo
$a;
} catch(
exceptionError $e) {
    echo
$e;
}
?>


It will catch the undefined variable notice.

<?php
/**
* @package package.exceptions.errors
* @author Johan Barbier <barbier_johan@hotmail.com>
* @version 20071017
* @desc package transforming all php errors into catchable exceptions
*
*/

/**
* @name exceptionErrorGeneric
* @desc Generic exceptionError class. Overload Exception::__toString() method and Exception::__construct() method
*
*/
abstract class exceptionErrorGeneric extends Exception {
   
/**
     * @desc Error type
     *
     * @var string
     */
   
protected $sType;
   
   
/**
     * @desc Error file
     *
     * @var string
     */
   
protected $sErrFile;
   
   
/**
     * @desc Error line
     *
     * @var int
     */
   
protected $iErrLine;
   
   
/**
     * @desc Error context
     *
     * @var mixed
     */
   
protected $mVars;
   
   
/**
     * @desc is context enabled or not
     *
     * @var boolean
     */
   
protected $bContext;
   
   
/**
     * @desc constructor
     *
     * @param constant $cErrno
     * @param string $sErrStr
     * @param string $sErrFile
     * @param int $iErrLine
     * @param mixed $mVars
     * @param boolean $bContext
     */
   
public function __construct($cErrno, $sErrStr, $sErrFile, $iErrLine, $mVars, $bContext = false) {
       
parent::__construct($sErrStr, $cErrno);
       
$this->sErrFile = $sErrFile;
       
$this->iErrLine = $iErrLine;
       
$this->mVars = $mVars;
       
$this->bContext = $bContext;
    }
   
   
/**
     * @desc Exception::__toString() overloading
     *
     * @return string
     */
   
public function __toString() {
       
$sMsg = '<strong>'.$this->sType.'</strong><br />';
       
$sMsg .= $this->getMessage().'['.$this->getCode().']<br />';
       
$sMsg .= '<em>File</em> : '.$this->sErrFile.' on line '.$this->iErrLine.'<br />';
       
$sMsg.= '<em>Trace</em> :<br />'.$this->getTraceAsString().'<br />';
        if(
true === $this->bContext) {
           
$sMsg.= '<em>Context</em> :<br />'.print_r($this->mVars, true);
        }
        return
$sMsg;
    }
}

/**
* @desc exceptionErrors for Fatal errors
*
*/
class exceptionErrorError extends exceptionErrorGeneric {
    protected
$sType = 'Fatal error';
}

/**
* @desc exceptionErrors for Warnings
*
*/
class exceptionErrorWarning extends exceptionErrorGeneric {
    protected
$sType = 'Warning';
}

/**
* @desc exceptionErrors for Parse errors
*
*/
class exceptionErrorParseError extends exceptionErrorGeneric {
    protected
$sType = 'Parse error';
}

/**
* @desc exceptionErrors for Notice
*
*/
class exceptionErrorNotice extends exceptionErrorGeneric {
    protected
$sType = 'Notice';
}

/**
* @desc exceptionErrors for Core errors
*
*/
class exceptionErrorCoreError extends exceptionErrorGeneric {
    protected
$sType = 'Core error';
}

/**
* @desc exceptionErrors for Core warnings
*
*/
class exceptionErrorCoreWarning extends exceptionErrorGeneric {
    protected
$sType = 'Core warning';
}

/**
* @desc exceptionErrors for Compile errors
*
*/
class exceptionErrorCompileError extends exceptionErrorGeneric {
    protected
$sType = 'Compile error';
}

/**
* @desc exceptionErrors for Compile warnings
*
*/
class exceptionErrorCompileWarning extends exceptionErrorGeneric {
    protected
$sType = 'Compile warning';
}

/**
* @desc exceptionErrors for User errors
*
*/
class exceptionErrorUserError extends exceptionErrorGeneric {
    protected
$sType = 'User error';
}

/**
* @desc exceptionErrors for User warnings
*
*/
class exceptionErrorUserWarning extends exceptionErrorGeneric {
    protected
$sType = 'User warning';
}

/**
* @desc exceptionErrors for User notices
*
*/
class exceptionErrorUserNotice extends exceptionErrorGeneric {
    protected
$sType = 'User notice';
}

/**
* @desc exceptionErrors for Strict errors
*
*/
class exceptionErrorStrictError extends exceptionErrorGeneric {
    protected
$sType = 'Strict error';
}

/**
* @desc exceptionErrors for not handled yet errors
*
*/
class exceptionErrorNotHandledYet extends exceptionErrorGeneric {
    protected
$sType = 'Not handled yet';
}

/**
* @desc error handler, calling correct exceptionError type
*
*/
class exceptionErrorHandler {
   
/**
     * @desc translation between context error and exceptionError type of class
     *
     * @var array
     */
   
public static $aTrans = array (
       
E_ERROR => 'exceptionErrorError',
       
E_WARNING => 'exceptionErrorWarning',
       
E_PARSE => 'exceptionErrorParseError',
       
E_NOTICE => 'exceptionErrorNotice',
       
E_CORE_ERROR => 'exceptionErrorCoreError',
       
E_CORE_WARNING => 'exceptionErrorCoreWarning',
       
E_COMPILE_ERROR => 'exceptionErrorCompileError',
       
E_COMPILE_WARNING => 'exceptionErrorCompileWarning',
       
E_USER_ERROR => 'exceptionErrorUserError',
       
E_USER_WARNING => 'exceptionErrorUserWarning',
       
E_USER_NOTICE => 'exceptionErrorUserNotice',
       
E_STRICT => 'exceptionErrorStrictError'
   
);
   
   
/**
     * @desc is context enabled or not
     *
     * @var boolean
     */
   
public static $bContext = false;
   
   
/**
     * @desc constructor, optional bContext boolean can be given if you want context to be displayed or not
     *
     * @param boolean $bContext (optional, default = false)
     */
   
public function __construct($bContext = false) {
       
self::$bContext = $bContext;
       
set_error_handler(array ($this, 'errorHandler'));
    }

   
/**
     * @desc error handler
     *
     * @param constant $cErrno
     * @param string $sErrStr
     * @param string $sErrFile
     * @param int $iErrLine
     * @param mixed $mVars
     */
   
public function errorHandler ($cErrno, $sErrStr, $sErrFile, $iErrLine, $mVars) {
        if(!isset(
self::$aTrans[$cErrno])) {
            throw new
exceptionErrorNotHandledYet($cErrno, $sErrStr, $sErrFile, $iErrLine, $mVars, self::$bContext);
        } else {
            throw new
self::$aTrans[$cErrno]($cErrno, $sErrStr, $sErrFile, $iErrLine, $mVars, self::$bContext);
        }
    }
}
?>



DB Connection Function with error handling and email failure notices
Categories : PHP, MySQL, Errors and Logging, Databases, Errors and Logging
A Custom Error Handling And Debugging Class
Categories : PHP, PHP Classes, Debugging, Errors and Logging
Building a basic error handler with custom error types
Categories : PHP, PHP Classes, Errors and Logging
[PHP5] PHP Debugger and Helper
Categories : PHP, PHP Classes, Errors and Logging, Debugging, XML
very simple ftp class
Categories : PHP, PHP Classes, FTP
PHP Paypal IPN Integration Class v1.0.0
Categories : PHP, PHP Classes, Payment Gateways
A Timing Class
Categories : PHP, PHP Classes, Date Time
The class to check load time of your script VERY usefull for relatively slow applications, but not only..
Categories : PHP, PHP Classes, Debugging
Create HTML forms dynamicly using Javascript & PHP
Categories : PHP, PHP Classes, Java Script
usercounter class
Categories : PHP, PHP Classes, Databases, MySQL, Environment Variables
RSS parser. Parses RSS into an array. Quick and nasty but does the job. No checking is done for correct Tags, only correct XML. PHP4 needed to display result (uses print_r).
Categories : PHP, XML, PHP Classes, Rich Site Summary (RSS)
ElfReader: An ELF (Executable and Linking Format) header information in PHP. Shows how to use the UNPACK function to read data.
Categories : PHP, Linux, PHP Classes
A simple function to prevent undefined $_POST/$_GET/$_SESSION variable errors
Categories : PHP, Variables, Errors and Logging
an example of the cyberlib payment class
Categories : PHP, PHP Classes, Ecommerce, Credit Cards
Power Form Validation
Categories : PHP, PHP Classes, Data Validation