Try Catch block in php 5.3.5 not working [closed]
Well I have a WampServer installed on my WinXP box with PHP 3.5.3 and apache 2.2.17. Strangely the try catch block doesnt work, after some googling I could only find that the bug lies in eaccelerator (but phpinfo showed no trace of it).
where am i going wrong??
try{
echo "from try";
parent::conect();
}catch(Exception $e){
echo "from catch";}
My output should be
from tryfrom catch
But instead i get
from try
Fatal Error: cannot access parent:: when no class...
Notice: Undefined variable: a in blah on line 4
This is not an exception. It is an error message. Or more specifically a notice, which classifies as debug message.
Try/Catch will not capture them in a default PHP setup. You would need an error handler which converts them into an exception. But that would be stupid.
In your case you should just define your variable beforehand. (In a few other cases you would test it with isset()
).
$a = 0;
try {
echo "from try";
$a+=1;
}
catch(Exception $e) {
echo "from catch";
}
The try/catch is redundant then. Neither echo
nor the +
operation will trigger an exception.
Notice is not Exception. You can not catch it by try catch.
精彩评论