As usual you will have to write an exception in try and catch block. So that when an exception is thrown, the code following it will not be executed, and PHP will try to find the matching catch block. The following example has a proper code :
PHP Code:
<?php
function CheckDemo($number)
{
if($number>5)
{
throw new Exception("Value must be 5 or below");
}
return true;
}
try
{
checkNum(2);
echo 'If you see this, the number is 5 or below';
}
catch(Exception $e)
{
echo 'Message: ' .$e->getMessage();
}
?>
Bookmarks