Information and support for products of WithinWeb.com

 header image 2

Simple PHP 5 error handling

May 14th, 2012 · No Comments

<?php
//create function with an exception
function checkNum($number)
{
if($number>1)
{
throw new Exception(“Value must be 1 or below”);
}
return true;
}

//trigger exception in a “try” block
try
{
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.