开发者

Try Catch block in php 5.3.5 not working [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its cur开发者_Python百科rent form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜