I am using Doctrine's dbal
service in my Symfony2 app.
I query a non-existent table, which throws an error:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'log.requests_20130311' doesn't exist.
Symfony2 catches this before I can, even in a try-catch
block. I don't want this to kill my application. How can I handle it?
Per @Coussinsky's comment, you need to have a \
in front of your exception:
try {
$result_set = $this->connection->query($sql);
} catch (\Exception $e) {
return 0;
}
Doctrines DBAL layer is a wrapper around PDO, so you should be able to do:
try {
// Query your non-existent table
} catch (\PDOException $e) {
// Deal with it without killing your app
}
http://symfony.com/doc/current/cookbook/doctrine/dbal.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With