View Single Post
Old 02-27-2008, 11:14 PM   #6 (permalink)
xenon
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

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.
xenon is offline  
Reply With Quote