joomla-framework
joomla-framework copied to clipboard
Fatal when MysqlExporter::__toString() throws an Exception
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.
I think I would return $e->getMessage()
.
I was thinking the same thing, @eddieajau.
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 ? ...