Search code examples
phperror-handlingjoomlacomponentsbackend

Joomla backend disable eerror reporting in my component


I am developing a joomla component for backend. For now for debugging i just put die() to place where i need to stop and display debug info all the way to figure out what happens. I did not use XDEBUG because there many query's and i need to check many results at once.

But i have a problem. When i get error in my SQL query because some error in script or my mistake instead just put it at bottom at all other info Joomla back from, for example page: /administrator/index.php?option=com_xyz&view=build to /administrator/ trowing away all debug info, so i just cant figure out where error happens or which SQL query cause this trouble.

So i have similar error on top main admin page inside red block:

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 3

All i want it did not catch errors and allow me to see it with other my script output.

So how disable joomla reporting in my component, temporary.


Solution

  • First i use:

    restore_exception_handler();
    

    and then

    try {
         $dict_data = $db->loadObject();
    }
    catch (Exception $e){
        $trace = $e->getTrace();
        echo $e->getMessage().' in '.$e->getFile().' on line '.$e->getLine().' called from '.$trace[0]['file'].' on line '.$trace[0]['line'];
        die();
    }