SEO TIPS

2013 SEO Tips

BLOGGER TIPS

Best Blogger Tips

INCREASE TRAFFIC

Expert Tips To increase traffic

ONLINE TOOLS

100 Online Tools

INCREASE INDEX RATE

Increase your google index rate

IMPROVE ALEXA RANK

Improve alexa rank

SEO TOOLS

51 SEO Tools

PHP SCRIPT

Essential PHP Scripts

Exception handling php for errors

Exception Handling PHP Errors allows you to change the normal flow of your code and execute a special block of code when a specific exception occures.php5 and php6 offer exception handling.

Exception handling php for errors
Exception handling php for errors


Lets say you want to withdraw $200 bucks from an ATM.but may be you are required to have a minimum balance of $1000 and this withdrawl will put you under $1000 that is not allowed.

transcation failed.

here is how this scenario might play out in PHP code with the help of exception handling to catch the failure.

<?php
       function checkbalance($balance) {
       if ($balance < 1000) {
         throw new exception ("Balance is less than $1000.");
         }
return true;
}
try{
checkbalance(999) ;
echo 'Balance is above $1000.';
}
catch (Exception $e) {
echo 'error: ' . $e->getmessage();
}
?>
  

Exception handling consists of three blocks of code:

php exception handling example

Try (Exception handling php)

This block is where you check to see if your value is what you except it to be.

if it is , everything and your code continues on its way. If not an exception has occured. In programmers , an exception is thrown.

And when something is thrown there needs to be something to catch it.if there is an exception the "catch" block code is executed. if not the code will continue as normal.

Throw (Exception handling php)

The "throw" commands the "catch" block and sends it an error message. each "thro" has at least one "catch".

Catch (Exception handling php)

An object is created with the exception information.More information on objects , on the facing page.

Incoming Search Terms

php throw exception
php exception handling
exception handling in php
php file handling
php handling exceptions
php handle exception
php exception types
php exception handling example

0 comments :