catch exceptions
authorChristian Weiske <cweiske@cweiske.de>
Thu, 13 Feb 2014 19:31:10 +0000 (20:31 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Thu, 13 Feb 2014 19:31:10 +0000 (20:31 +0100)
src/bdrem/UserInterface.php

index 5fb028b4a964221f884fbd7bd972b6408849f7b3..da5e9a3001cdb81669d7926a215c299c536b32f5 100644 (file)
@@ -7,21 +7,27 @@ abstract class UserInterface
 
     public function run()
     {
-        $this->config = new Config();
-        $this->config->load();
-        $this->config->date = date('Y-m-d');
-        setlocale(LC_TIME, $this->config->locale);
-        $source = $this->config->loadSource();
+        try {
+            $this->config = new Config();
+            $this->config->load();
+            $this->config->date = date('Y-m-d');
+            setlocale(LC_TIME, $this->config->locale);
+            $source = $this->config->loadSource();
 
-        $parser = $this->loadParameters();
-        $this->parseParameters($parser);
+            $parser = $this->loadParameters();
+            $this->parseParameters($parser);
 
-        $arEvents = $source->getEvents(
-            $this->config->date,
-            $this->config->daysPrev, $this->config->daysNext
-        );
-        usort($arEvents, '\\bdrem\\Event::compare');
-        $this->render($arEvents);
+            $arEvents = $source->getEvents(
+                $this->config->date,
+                $this->config->daysPrev, $this->config->daysNext
+            );
+            usort($arEvents, '\\bdrem\\Event::compare');
+            $this->render($arEvents);
+        } catch (\Exception $e) {
+            $this->preRenderParameterError();
+            echo 'Exception: ' . $e->getCode() . ' ' . $e->getMessage() . "\n";
+            exit(1);
+        }
     }
 
     protected function loadParameters()