joomla-framework icon indicating copy to clipboard operation
joomla-framework copied to clipboard

Fatal when MysqlExporter::__toString() throws an Exception

Open asika32764 opened this issue 11 years ago • 3 comments

When I using MysqlExporter to export a table, if this table not exists, the DatabaseDriver will throw an exception.

But php return this message:

Fatal error: Method Joomla\Database\Mysql\MysqlExporter::__toString() 
must not throw an exception in {CALLED_PATH} on line xx

If I modified __toString() method:

public function __toString()
{
    // Check everything is ok to run first.
    try
    {
        $this->check();

        // Get the format.
        switch ($this->asFormat)
        {
            case 'xml':
            default:
                $buffer = $this->buildXml();
                break;
        }
    }
    catch(\Exception $e)
    {
        echo $e;

        return false;
    }

    return $buffer;
}

It works and return the correct exception message.

But I don't know how to fix this problem in a right way.

asika32764 avatar Nov 12 '13 15:11 asika32764

I think I would return $e->getMessage().

eddieajau avatar Nov 13 '13 09:11 eddieajau

I was thinking the same thing, @eddieajau.

dongilbert avatar Nov 13 '13 15:11 dongilbert

So how will the calling class know if the string that it receives is the representation of the object or the representation of an exception message ? Would you check the string for XML or something ? ...

elkuku avatar Nov 13 '13 15:11 elkuku