Afficher un message
Vieux 26/03/2008, 17h04   #1
Daniel Klein
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Confused about catching runtime errors

When I run the following code the following errors end up in my error log
file:

PHP Notice: Undefined variable: n in C:\home\php\sandbox\error.php on line
14
PHP Fatal error:Call to a member function fun() on a non-object in
C:\home\php\sandbox\error.php on line 14


<?php
class Numpty {
public function fun() {
return 'Have fun!';
}
}

$n = new Numpty();
echo $n->fun();

unset($n);

try {
echo $n->fun(); //this is line 14
}
catch (Exception $e) {
echo 'Gotcha!';
}
echo 'Done';
?>


You will notice that I have a 'try/catch' block around the line that is
causing the error. Why doesn't this code catch the error?

What is the PHP way of handling this situation?

I'm reading up now on custom error handlers but I decided to post this now
in case that leads to another wgc ;-)

Daniel Klein
  Réponse avec citation
 
Page generated in 0,04573 seconds with 9 queries