Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Catching a runtime exception in PHP

Tags:

exception

php

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?

like image 994
Ariod Avatar asked Apr 20 '26 08:04

Ariod


1 Answers

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');
like image 114
Greg Avatar answered Apr 21 '26 20:04

Greg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!