PHP runtime exception exception

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 does not seem to be caught:

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

Did I miss something?

+3
source share
2 answers

It seems like it is throwing an error, and not throwing an exception.

You can 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');
+7
source

This is not like an exception, more like a regular PHP error.

, , eAccelerator . , eAccelerator, Exception, : |

0

Source: https://habr.com/ru/post/1714848/


All Articles