How can I handle Doctrine errors?

I am using the Doctrine dbal service in my Symfony2 application.

I am querying a nonexistent table that causes an error:

SQLSTATE [42S02]: The base table or view was not found: 1146 The table "log.requests_20130311" does not exist.

Symfony2 catches this sooner than I can, even in a try-catch . I do not want this to kill my application. How can I handle this?

+4
source share
2 answers

In @Coussinsky's comment, you need to have \ before your exception:

 try { $result_set = $this->connection->query($sql); } catch (\Exception $e) { return 0; } 
+4
source

The Doctrines DBAL is the wrapper around the PDO, so you should be able to:

 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

+3
source

Source: https://habr.com/ru/post/1468842/


All Articles