From b670b16ca22bdeb666b395a45706ec3ec172ac0a Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Wed, 13 May 2020 22:33:02 +0200 Subject: [PATCH] Catch various exceptions on the index --- index.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/index.php b/index.php index 0b7772c..a62d032 100644 --- a/index.php +++ b/index.php @@ -19,7 +19,11 @@ if (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], '/index.ph } if (is_file(__DIR__ . '/config/config.yml')) { - Config::setFile(__DIR__ . '/config/config.yml'); + try { + Config::setFile(__DIR__ . '/config/config.yml'); + } catch (Exception $e) { + die('Could not load config file: ' . $e->getMessage()); + } } // Create app. @@ -50,7 +54,11 @@ $container['locale'] = LocaleManager::getInstance(); $app->add(new LocaleMiddleware($container)); // Smarty. -$container['view'] = ViewFactory::create($container); +try { + $container['view'] = ViewFactory::create($container); +} catch (SmartyException $e) { + die('Could not load Smarty: ' . $e->getMessage()); +} // Controllers. $frontController = new FrontController($container); @@ -105,4 +113,7 @@ try { $app->run(); } catch (SmartyException $e) { die('Smarty could not compile the template file: ' . $e->getMessage()); +} catch (Throwable $e) { + // Last resort if the error has not been caught by the error handler for some reason. + die('Error when starting the app: ' . $e->getMessage()); }