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 : PHP5 Exceptions
Categories : PHP, PHP Classes, Errors and Logging Click here to Update Your Picture
Joseph Crawford
Date : Sep 18th 2004
Grade : 3 of 5 (graded 7 times)
Viewed : 4240
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Joseph Crawford
Action : Grade This Code Example
Tools : My Examples List

 
Like this code?
Show the author your appreciation.
Submit your own code examples 
 

Handling errors in PHP 4 as you all might know has always been a pain in the ass. Along with PHP 5 has comes much better exception handling. When you want to throw an exception you can use code like the following

<?
try {
   echo
3 / 0;
}
catch (
Exception $e) {
   echo
'Line: '.$e->getLine().'<br>';
   echo
'File: '.$e->getFile().'<br>';
   echo
'<br>Trace: <br>';
   echo
'<pre>';
   
print_r($e->getTrace());
   echo
'</pre>';
}
?>


this code will throw an error because you cannot divide by 0, you will see how the information is printed to the screen.

Now you can also extend the Exception class for much more extendability.

Class DatabaseException extends Exception {
     public function __construct($msg) {
          parent::__construct($msg);
     }
}


when you want to throw an error, say you have this

$query = mysql_query("SELECT * FROM table") or die(mysql_error());


this is how we would have done this before, now we can do this differently to show a nice message to the user without actually stopping everything, you can show a nice message formatted and fitted for your site design ;)

$query = mysql_query("SELECT * FROM table") or throw new DatabaseException('Database Query Failed!");


this code alone is not a complete sample however extending the exception class will allow you to create other methods that you can call to output the design before and after you call the parent::__construct() method.

I hope you guys like this new error handling, any questions use the comment system or weberdev@codebowl.com



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