WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
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 Resources
Web Development Content
Internet Security Software
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
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

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 : 4078
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  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);
        }
    }
}
?>



A Custom Error Handling And Debugging Class
Categories : PHP, PHP Classes, Debugging, Errors and Logging
[PHP5] PHP Debugger and Helper
Categories : PHP, PHP Classes, Errors and Logging, Debugging, XML
Building a basic error handler with custom error types
Categories : PHP, PHP Classes, Errors and Logging
DB Connection Function with error handling and email failure notices
Categories : PHP, MySQL, Errors and Logging, Databases, Errors and Logging
Recordset Class for MSSQL database
Categories : PHP Classes, Databases, PHP, MS SQL Server
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)
Returns Yahoo! Address Book and Messenger List as an Array
Categories : PHP, PHP Classes, CURL
Antispoof - a class to help prevent people hi-jacking and misusing parts of a website
Categories : PHP, PHP Classes, Security
Logging 404 errors in your custom statistics using Apache and a PHP script.
Categories : Apache, Web Servers, PHP, Errors and Logging
PHP Image Class
Categories : PHP, PHP Classes, Multimedia, GD image library
Open and Close your website in fixed times .
Categories : PHP, PHP Classes, Cron, Date Time
Writing Portable MySQL Code in PHP: Porting to Oracle, Microsoft SQL Server, Sybase, Interbase, PostgreSQL and other databases using ADODB class library.
Categories : MySQL, PHP, PHP Classes, ODBC, General SQL
Optimized Online users class
Categories : PHP, PHP Classes, Sessions
Object() = Custom __autoload + Singleton. "automagically" instantiates a class and always retuns the same instance of the same class. It's pretty useful when you want to have persistence in objects.
Categories : PHP, PHP Classes, Algorithms
Password Creator: This PHP code exmaple shows how to use bitwise operations on a single variable and using it as a flagged variable. The class generates passwords of a given length using specified characters and the flags.
Categories : PHP, PHP Classes, Algorithms, Security