Index: trunk/FACT++/src/magiclidar.cc
===================================================================
--- trunk/FACT++/src/magiclidar.cc	(revision 14959)
+++ trunk/FACT++/src/magiclidar.cc	(revision 14961)
@@ -85,4 +85,5 @@
 
         bool keepalive = false;
+        bool failed = false;
 
         stringstream is(str);
@@ -112,38 +113,47 @@
             else
             {
-                if (line.substr(0, 3)=="ZEN")
-                    data.fZd = stoi(line.substr(3));
-                if (line.substr(0, 2)=="AZ")
-                    data.fAz = stof(line.substr(2));
-
-                if (line.substr(0, 3)=="PBL")
-                    data.fPBL = stof(line.substr(3));
-                if (line.substr(0, 3)=="CHE")
-                    data.fCHE = stof(line.substr(3));
-                if (line.substr(0, 3)=="COT")
-                    data.fCOT = stof(line.substr(3));
-
-                if (line.substr(0, 2)=="T3")
-                    data.fT3 = stof(line.substr(2));
-                if (line.substr(0, 2)=="T6")
-                    data.fT6 = stof(line.substr(2));
-                if (line.substr(0, 2)=="T9")
-                    data.fT9 = stof(line.substr(2));
-                if (line.substr(0, 3)=="T12")
-                    data.fT12 = stof(line.substr(3));
-
-                if (line.substr(0, 4)=="HOUR")
-                    hh = stoi(line.substr(4));
-                if (line.substr(0, 6)=="MINUTS")
-                    mm = stoi(line.substr(6));
-                if (line.substr(0, 7)=="SECONDS")
-                    ss = stoi(line.substr(7));
-
-                if (line.substr(0, 4)=="YEAR")
-                    y = stoi(line.substr(4));
-                if (line.substr(0, 5)=="MONTH")
-                    m = stoi(line.substr(5));
-                if (line.substr(0, 3)=="DAY")
-                    d = stoi(line.substr(3));
+                try
+                {
+                    if (line.substr(0, 3)=="ZEN")
+                        data.fZd = stoi(line.substr(3));
+                    if (line.substr(0, 2)=="AZ")
+                        data.fAz = stof(line.substr(2));
+
+                    if (line.substr(0, 3)=="PBL")
+                        data.fPBL = stof(line.substr(3));
+                    if (line.substr(0, 3)=="CHE")
+                        data.fCHE = stof(line.substr(3));
+                    if (line.substr(0, 3)=="COT")
+                        data.fCOT = stof(line.substr(3));
+
+                    if (line.substr(0, 2)=="T3")
+                        data.fT3 = stof(line.substr(2));
+                    if (line.substr(0, 2)=="T6")
+                        data.fT6 = stof(line.substr(2));
+                    if (line.substr(0, 2)=="T9")
+                        data.fT9 = stof(line.substr(2));
+                    if (line.substr(0, 3)=="T12")
+                        data.fT12 = stof(line.substr(3));
+
+                    if (line.substr(0, 4)=="HOUR")
+                        hh = stoi(line.substr(4));
+                    if (line.substr(0, 6)=="MINUTS")
+                        mm = stoi(line.substr(6));
+                    if (line.substr(0, 7)=="SECONDS")
+                        ss = stoi(line.substr(7));
+
+                    if (line.substr(0, 4)=="YEAR")
+                        y = stoi(line.substr(4));
+                    if (line.substr(0, 5)=="MONTH")
+                        m = stoi(line.substr(5));
+                    if (line.substr(0, 3)=="DAY")
+                        d = stoi(line.substr(3));
+                }
+                catch (const exception &e)
+                {
+                    Warn("Conversion of received data failed");
+                    failed = true;
+                    break;
+                }
             }
         }
@@ -151,4 +161,7 @@
         if (!keepalive)
             PostClose(false);
+
+        if (failed)
+            return;
 
         try
