I'm trying to get my head around the order of operations related to Exceptions thrown into the Slim platform app and the final delivery of the page. Basically, if I throw an exception in the class, I would like Slim to deliver my beautiful Twig 500 page, but I can't even get Slim to deliver its own regular error page when the exception is thrown out of the route.
Given this constructor of the database class:
public function __construct(array $connection, \Slim\Slim $slim) {
$this->slim = $slim;
try {
$this->db = new \PDO(...);
$this->db->setAttribute(\PDO::ATTR_EMULATE_PREPARES, FALSE);
$this->db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
} catch (\PDOException $e) {
}
}
If I run $this->slim->error();, I get Fatal error: Uncaught exception 'Slim\Exception\Stop'.
Ideally, I would like to do something like:
- Log in through
$this-slim->log->error("Unable to connect to database."); - Stop trying to perform further actions in my DB class (so that everything fails and throws a fatal exception)
- 500.twig.
.