Probar Catch block en php 5.3.5 no funciona [cerrado]

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??

echo "from try";
}catch(Exception $e){
echo "from catch";}

Mi salida debería ser

from tryfrom catch

Pero en cambio consigo

from try
Fatal Error: cannot access parent:: when no class...

preguntado el 28 de agosto de 11 a las 03:08

I'm assuming you're not expecting try/catch to work from thin air. Where's your code? -

Can't reproduce, works for me. You'll need to give us a lot more detail. -

@deceze... what all do you need besides code? -

@all why am i getting dug down?? -

2 Respuestas

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 entrenador de animales 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";
catch(Exception $e) {
   echo "from catch";

The try/catch is redundant then. Neither echo ni la + operation will trigger an exception.

Respondido 28 ago 11, 08:08

Notice is not Exception. You can not catch it by try catch.

Respondido 28 ago 11, 08:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.