02-27-2008, 11:14 PM
|
#6 (permalink)
|
|
The Frequenter
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
|
The exceptions are not a way of ending your script. die and exit are made for that. Exceptions are used to treat various cases and act accordingly. For example:
Code:
function do_division($a, $b)
{
if( $b == 0 )
{
throw new Exception('The divisor cannot be 0!');
}
return ($a / $b);
}
try
{
echo 'Result: ' . do_division(2, 0);
}
catch(Exception $e)
{
echo $e->getMessage();
// use some default values
$a = 4;
$b = 2;
}
// continue execution ...
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
|
|
|
|