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 : 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 : 7142
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

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

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



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
Sort the results from a SELECT query (any number of columns) into an array automatically.
Categories : PHP, PHP Classes, Arrays, Databases, MySQL
usercounter class
Categories : PHP, PHP Classes, Databases, MySQL, Environment Variables
Most of the browsers, especially Internet Explorer, behave in different ways. Hence it become necessary to use Browser detection to fix the non standard behavior of the browser. This is a browser sniffer class that can be used for the above purpose.
Categories : PHP, PHP Classes, Browsers
Three Cool Classes and One Trick
Categories : PHP, PHP Classes, Graphics, Email
XTemplate, a template class for PHP
Categories : PHP Classes, HTML and PHP, PHP
Request Method Class - seful for situations like form processing or API development. Requires PHP5 for the magic __call() method.
Categories : PHP, PHP Classes, HTTP, Headers
A damaged image generator (class) for validating text. CAPTCHA - Completely Automated Public Turing test to tell Computers and Humans Apart
Categories : PHP, PHP Classes, Security, GD image library, Security
base64 with encryption - encode and decode sessions
Categories : PHP, PHP Classes, Encryption, Sessions
A Timing Class
Categories : PHP, PHP Classes, Date Time
Mssql database Manager
Categories : PHP, Databases, MS SQL Server, Classes and Objects, PHP Classes
A beginner's session handling class
Categories : PHP, PHP Classes, Sessions, Beginner Guides