Home arrow PHP arrow Page 3 - Error Handling In PHP (part 2)

Rolling Back - PHP

The first part of this article demonstrated basic errorhandling in PHP, explaining the various error types and illustrating theprocess of building a custom error handler. But that's just the tip ofthe iceberg - this concluding part goes a step further, showing you totrigger your own errors, and log error messages to a file, database oremail address.

TABLE OF CONTENTS:
  1. Error Handling In PHP (part 2)
  2. Raising Hell
  3. Rolling Back
  4. Turning Up The Heat
  5. Of Form And Function
  6. Buffer Zone
  7. Back To Class
  8. Endgame
By: icarus, (c) Melonfire
Rating: starstarstarstarstar / 11
April 09, 2002

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
PHP also comes with a restore_error_handler() function, which allows you to restore the previous error handler. This is useful if you need to switch between handlers in a single script. Consider the following simple example, which demonstrates:

<?php // custom error handler function eh($type, $msg, $file, $line, $context) { echo "This is the custom error handler speaking"; } // trigger a warning // this will be caught by the default handler // since nothing else has been defined trigger_error("Something bad happened", E_USER_WARNING); // define a new handler set_error_handler("eh"); // trigger another warning // this will be caught by the custom handler trigger_error("Something bad happened", E_USER_WARNING); // rollback to default handler restore_error_handler(); // trigger another warning // this will be caught by the default handler trigger_error("Something bad happened", E_USER_WARNING); ?>
Here's what the output looks like:

Warning: Something bad happened in /usr/local/apache/htdocs/x2.php on line 12 This is the custom error handler speaking Warning: Something bad happened in /usr/local/apache/htdocs/x2.php on line 26


 
 
>>> More PHP Articles          >>> More By icarus, (c) Melonfire
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: