views:

371

answers:

2

I am trying to catch a runtime exception that will be thrown by a function that is basically just a wrapper function for oci_execute(). For example:

try {   
    $SQL = "INSERT";
    ExecuteQuery($SQL);
} catch (Exception $e) {
    echo "<p>There was an error.</p>";
    echo $e->getMessage();
}

However, the exception doesn't appear to be caught:

...
ociexecute() [function.ociexecute]: ORA-00925: missing INTO keyword
...

Am I missing something here?

A: 

It doesn't seem like an Exception, more like a plain PHP error.

If it is, check if you have eAccelerator and what version you have. I had a problem a while ago, there was eAccelerator bug that didn't catch Exception and I had to turn it off :|

usoban
+2  A: 

It looks like it's triggering an error rather than throwing an exception.

You could convert errors to exceptions using set_error_handler() - something like this:

function errorHandler($number, $string, $file = 'Unknown', $line = 0, $context = array())
{
    if (($number == E_NOTICE) || ($number == E_STRICT))
     return false;

    if (!error_reporting())
     return false;

    throw new Exception($string, $number);

    return true;
}

set_error_handler('errorHandler');
Greg
If you want to convert errors into exceptions you may want to take a look at PHP's own ErrorException: http://docs.php.net/manual/en/class.errorexception.php
Josh Davis