Skip to content
This repository has been archived by the owner on Nov 26, 2017. It is now read-only.

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

Open
asika32764 opened this issue Nov 12, 2013 · 3 comments
Open

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

asika32764 opened this issue Nov 12, 2013 · 3 comments

Comments

@asika32764
Copy link
Contributor

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
Copy link
Contributor

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

@dongilbert
Copy link
Contributor

I was thinking the same thing, @eddieajau.

@elkuku
Copy link
Contributor

elkuku commented Nov 13, 2013

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants