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 : Building a basic error handler with custom error types
Categories : PHP, PHP Classes, Errors and Logging Click here to Update Your Picture
Ben Barnett
Date : Jun 17th 2004
Grade : 4 of 5 (graded 2 times)
Viewed : 8567
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Ben Barnett
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

Error Handling Class

@author Ben Barnett <ludge@spymac.com>
Code for: Setting vars, handling errors, mailing an error report and writing to an error log.

<?php
class error_handle
{
   
/**
* The constructor function for error_handle.
* sets the error handler to the custom one below
*/
function error_handle()
    {
   
   
// Sets the error handler to this one rather than default
    // Parameters are the object containing the function and the
    // function itsself. This is because the function is inside a class.
   
set_error_handler( array( &$this, 'error_handler' ) );
   
 
    }

 
/**
  * The error handler set by set_error_handler()
  *
  * Checks to see what sort of error is being triggered. It can catch any of the E_WARNING, E_ERROR and E_NOTICE as well as the
  * E_USER_* errors. You can also add your own custom types by adding them like I have done with BIG_SCARY_ERROR. Where it says to
  * add your own code, that is where you put the code to be executed when the error of that type occurs.
  *
  * @param string $error_type The type of error being handled.
  * @param string $error_message The error message being handled.
  * @param string $error_file The file where the error occurred.
  * @param integer $error_line The line where the error occurred.
  * @param string $error_context The context in which the error occurred.
  * @return boolean
  */
 
function error_handler($error_type, $error_message, $error_file, $error_line, $error_context)
  {
   switch(
$error_type)
    {
    case
E_ERROR:
    case
E_USER_ERROR:
   
// Add your own code here!
   
echo '<p class="error">'.$error_message,' (An error type ',$error_type,' occurred). The administrator has been notified. This page might not function correctly.<br /></p>'
    break;
     
     
    case
E_WARNING:
    case
E_USER_WARNING:
   
// Add your own code here!
   
echo '<p class="error">'.$error_message,' (An error type ',$error_type,' occurred). The administrator has been notified. This page might not function correctly.<br /></p>';
    break;

    case
E_NOTICE:
    case
E_USER_NOTICE:
   
// Add your own code here!
   
echo '<p class="error">'.$error_message,' (An error type ',$error_type,' occurred). The administrator has been notified. This page might not function correctly.<br /></p>';
    break;
   
    case
BIG_SCARY_ERROR:
    echo
'A *huge* scary error has been seen skulking around on line '.$error_line.' of '.$error_file.'! It\'s shouting "'.$error_message.'"';
    break;
    }
return
true;
  }

}

?>


To use this error handler, put in in a file, and include it into your script. Then, instantiate it (eg $error_handler = new error_handler() ). The whenever an error occurs, the class will catch it. To trigger your own errors do:

trigger_error('error message typed here', E_USER_ERROR);


(where the bit in capitals is the type you want to trigger).
So you can do this to trigger a custom error type:

trigger_error('I'm going to eat your PHP code!!! Bwahahahahaaa', BIG_SCARY_ERROR);



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
PHP5 Exceptions
Categories : PHP, PHP Classes, Errors and Logging
[PHP5] PHP Debugger and Helper
Categories : PHP, PHP Classes, Errors and Logging, Debugging, XML
an example of the cyberlib payment class
Categories : PHP, PHP Classes, Ecommerce, Credit Cards
.htpassword manager for apache
Categories : PHP, PHP Classes, Authentication, Apache
Freshmeat.net XML-RPC - This class is meant to query Freshmeat for information about registered projects.
Categories : PHP, PHP Classes, XML, Web Services
Browser Detecor Class
Categories : PHP Classes, PHP, HTML
Blueshoes PHP Application Framework
Categories : PHP, Frameworks, PHP Classes
Power Form Validation
Categories : PHP, PHP Classes, Data Validation
Class for sending mail with MIME attachments in multipart format using external sendmail, mimencode and zip
Categories : Email, Network, PHP, PHP Classes
Class to convert any document, that can be read by MS Word, to another format supported by Word.
Categories : PHP Classes, PHP, Windows 2000, Microsoft Word, WinNT
A PHP Calendar function with CSS : add a cool calendar to any php page by just adding a calendar class based function.
Categories : PHP, PHP Classes, Calendar, Date Time
Simple Mini Poll class library (SimPoll)
Categories : PHP, PHP Classes, Databases, MySQL, Complete Programs
Client classes for Dictionary servers UPDATED: 2000-06-06
Categories : Network, Search, Complete Programs, PHP Classes, PHP