Welcome Guest, Not a member yet? Register   Sign In
Can't seem to be able to extend the exception class
#1

[eluser]keld[/eluser]
Hello,

I'm trying to extend the exception class.
I have a function to insert records in the DB that looks like this:
Code:
function addIngredientDB()
    {
        
        $data=array(
            'name'=>$_POST['name'],
            'nameuri'=>$_POST['nameuri'],
            'picture'=>$_POST['photourl1'],
            'definition'=>$_POST['definition'],
        );
        try
        {
            $Qinsert=$this->db->insert('mytbl', $data);
            if(!$Qinsert){
                $erronum=$this->db->_error_number();
                $erromess=$this->db->_error_message();
                throw new MY_Exceptions($erromess, $erronum);
            }
            return true;
        }
        catch(MY_Exceptions $e)
        {
            echo $e->insertDBError();
            $this->firephp->log($e->insertDBError(), 'insert error');
        }
    }

But for some reason when $Qinsert = false, i never go into my catch nor in the if. It seems like the db->insert() catch it before me and do it's own thing.
I have added a MY_Exceptions class in the libraries folder. It's auto loaded right?

This is my exceptions class:
Code:
class MY_Exceptions extends CI_Exceptions
{
    function __MY_Exceptions()
    {
        parent::CI_Exceptions();
    }

    function insertDBError($emess, $enum)
    {
        $errorMsg="Error during insertion: Error message is ".$emess." and error number is: ".$enum;
        return $errorMsg;
    }
}

Thank you.




Theme © iAndrew 2016 - Forum software by © MyBB