Monday, 15 September 2014

php throw exception stop execution -



php throw exception stop execution -

i have code:

function divide($a,$b){ try{ if($b==0){ throw new exception("second variable can not 0"); } homecoming $a/$b; } catch(exception $e){ echo $e->getmessage(); } } echo divide(20,0); echo "done";

it throws exception when sec parameter 0. how can stop done printing?

don't grab exception in divide() , grab later:

function divide($a,$b){ if($b==0){ throw new exception("second variable can not 0"); } homecoming $a/$b; } seek { echo divide(20,0); echo "done"; } catch(exception $e){ echo $e->getmessage(); }

php exception

No comments:

Post a Comment