I’m a php newbie so this might sound trivial
Here is my php code
<?php
try
{
echo "Hello";
}
catch (Exception $e)
{
echo $e;
}
?>
This outputs Hello
Now i modified the code to get an exception
<?php
try
{
ech "Hello";
}
catch (Exception $e)
{
echo $e;
}
?>
But it prints nothing. Isn’t the catch supposed to print the error.Or am i doing some thing wrong
No, this is a syntax error (or parse error in PHP terms). The code never gets executed in the first place, so no exceptions can be thrown.
It should also be noted that the PHP core functions do not throw exceptions neither because exceptions got introduced with PHP 5 and they did not remove the old error system. So now you have to deal with errors (core, old extensions) and exceptions (new OO extensions, userland code) simultaneously. You can partially avoid this with the
ErrorException(see example on linked manual page) but it’s still a pain.