Catch various exceptions on the index

This commit is contained in:
Pierre Rudloff 2020-05-13 22:33:02 +02:00
parent 75052e58f3
commit b670b16ca2

View file

@ -19,7 +19,11 @@ if (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], '/index.ph
} }
if (is_file(__DIR__ . '/config/config.yml')) { if (is_file(__DIR__ . '/config/config.yml')) {
try {
Config::setFile(__DIR__ . '/config/config.yml'); Config::setFile(__DIR__ . '/config/config.yml');
} catch (Exception $e) {
die('Could not load config file: ' . $e->getMessage());
}
} }
// Create app. // Create app.
@ -50,7 +54,11 @@ $container['locale'] = LocaleManager::getInstance();
$app->add(new LocaleMiddleware($container)); $app->add(new LocaleMiddleware($container));
// Smarty. // Smarty.
try {
$container['view'] = ViewFactory::create($container); $container['view'] = ViewFactory::create($container);
} catch (SmartyException $e) {
die('Could not load Smarty: ' . $e->getMessage());
}
// Controllers. // Controllers.
$frontController = new FrontController($container); $frontController = new FrontController($container);
@ -105,4 +113,7 @@ try {
$app->run(); $app->run();
} catch (SmartyException $e) { } catch (SmartyException $e) {
die('Smarty could not compile the template file: ' . $e->getMessage()); 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());
} }