function calcFactorial($num) // This function will calculate the factorial of variable passed in arguement.
{
try
{
if (is_null($num))
{
throw new Exception('NULL Value Exception.');
}
else
{
$result = 1;
for($i = 1; $i<=$num;$i++)
{
$result = $result * $i;
}
echo "
Factorial is ".$result;
}
}
catch(Exception $e)
{
echo '
Caught exception: ', $e->getMessage();
}
try{
$result = RNCPHP\ROQL::queryObject("SELECT Contact From Contact");
}catch(Exception $e)
{
echo '
Caught exception: ', $e->getMessage();
}
$result2 = RNCPHP\ROQL::queryObject("SELECT Contact From Contact"); // NOK {{ROQL must be placed inside a try-catch block.}}
}
$x = 4;
$y;
calcFactorial($x); // Will not throw error as $x has a valid value assigned.
calcFactorial($y); // Will throw error as $y has no value assigned.
?>