joomla / joomla-framework

[READ-ONLY] This repo is no longer in active development. Please see https://github.com/joomla-framework for the individual Framework packages.
http://framework.joomla.org
GNU General Public License v2.0
189 stars 140 forks source link

Fatal when MysqlExporter::__toString() throws an Exception #276

Open asika32764 opened 11 years ago

asika32764 commented 11 years ago

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.

eddieajau commented 11 years ago

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

dongilbert commented 11 years ago

I was thinking the same thing, @eddieajau.

elkuku commented 11 years ago

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 ? ...