Information and support for products of

 header image 2

Simple PHP 5 error handling

May 14th, 2012 · No Comments

//create function with an exception
function checkNum($number)
throw new Exception(“Value must be 1 or below”);
return true;

//trigger exception in a “try” block
checkNum(2);//If the exception is thrown, this text will not be shownecho ‘If you see this, the number is 1 or below’;}
//catch exception
catch(Exception $e)
echo ‘Message: ‘ .$e->getMessage();

Tags: General PHP

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

You must log in to post a comment.