- Joined
- Jul 4, 2004
- Messages
- 211
- Reaction score
- 0
I am trying to write a try / catch statement to catch any error (Exception $e) and then detect if debug is on, or if the user is admin and can view errors, if they arent it just says something was wrong and documents the error and notifies me.
However, the try / catch will not catch any errors. Such as:
As you can see, I am intentionally trying to break it by leaving the ; off of the echo statement, however, it does not catch this error, rather display the error message and move on.
I am told I do not need to throw an exception for try / catch to work, and that it should catch stuff like this, can anyone confirm this and maybe say what I am doing wrong?
Thanks.
PS: Should be noted I am using PHP5.2.3.
However, the try / catch will not catch any errors. Such as:
PHP:
<?php
try
{
echo "what"
} catch (Exception $e)
{
if (user is admin || debug is on)
{
print the error and maybe some debug info.
} else
{
echo "Print some basic *There was a problem* error message, and that the Admin has been notified";
}
}
?>
I am told I do not need to throw an exception for try / catch to work, and that it should catch stuff like this, can anyone confirm this and maybe say what I am doing wrong?
Thanks.
PS: Should be noted I am using PHP5.2.3.
). Now, if I try to create a new database object to execute a query and place try / catch handlers around both the object call as the query I can be certain that if the database object isn't created properly it will also not try to execute the query - something which might for instance save your ass if you use 2 databases and you made a call to the other one previously (since PHP's default behaviour when no database instance is given is to use the last used instance). Now you can of course use statements like if(!$instance) die(), but using the exception handler these become obsolute and errors are handled much more gracefully.
