[Liblas-commits] hg: add some try/catch blocks, just in case

liblas-commits at liblas.org liblas-commits at liblas.org
Tue Jan 4 18:39:46 EST 2011


details:   http://hg.liblas.orghg/rev/86ba5e9da0dd
changeset: 2685:86ba5e9da0dd
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Tue Jan 04 15:39:40 2011 -0800
description:
add some try/catch blocks, just in case

diffstat:

 src/detail/reader/zipreader.cpp |  37 ++++++++++++++++++++++++++++++++-----
 src/detail/writer/zipwriter.cpp |  40 +++++++++++++++++++++++++++++++++-------
 2 files changed, 65 insertions(+), 12 deletions(-)

diffs (132 lines):

diff -r 20f07b581c9c -r 86ba5e9da0dd src/detail/reader/zipreader.cpp
--- a/src/detail/reader/zipreader.cpp	Tue Jan 04 12:42:06 2011 -0800
+++ b/src/detail/reader/zipreader.cpp	Tue Jan 04 15:39:40 2011 -0800
@@ -106,14 +106,31 @@
     // we'll create a point reader at this point.
     if (!m_unzipper)
     {
-        m_unzipper = new LASunzipper();
+        try
+        {
+            m_unzipper = new LASunzipper();
+        }
+        catch(...)
+        {
+            throw liblas_error("Failed to open laszip decompression engine (1)"); 
+        }
 
         PointFormatName format = m_header->GetDataFormatId();
         m_zipPoint = new ZipPoint(format);
 
-        unsigned int stat = m_unzipper->open(m_ifs, m_zipPoint->m_num_items, m_zipPoint->m_items, LASzip::COMPRESSION_DEFAULT);
+        unsigned int stat = 1;
+        try
+        {
+            stat = m_unzipper->open(m_ifs, m_zipPoint->m_num_items, m_zipPoint->m_items, LASzip::COMPRESSION_DEFAULT);
+        }
+        catch(...)
+        {
+            throw liblas_error("Failed to open laszip decompression engine (2)"); 
+        }
         if (stat != 0)
-            throw liblas_error("Failed to open laszip decompression engine"); 
+        {
+            throw liblas_error("Failed to open laszip decompression engine (3)"); 
+        }
     }
 
     return;
@@ -183,9 +200,19 @@
     //////++m_current;
     //////*m_point = m_point_reader->GetPoint();
 
-    bool ok = m_unzipper->read(m_zipPoint->m_lz_point);
+    bool ok = false;
+    try
+    {
+        ok = m_unzipper->read(m_zipPoint->m_lz_point);
+    }
+    catch(...)
+    {
+        throw liblas_error("Error reading compressed point data (1)");
+    }
     if (!ok)
-        throw liblas_error("Error reading compressed point data");
+    {
+        throw liblas_error("Error reading compressed point data (2)");
+    }
 
     std::vector<boost::uint8_t> v(m_zipPoint->m_lz_point_size);
     for (unsigned int i=0; i<m_zipPoint->m_lz_point_size; i++)
diff -r 20f07b581c9c -r 86ba5e9da0dd src/detail/writer/zipwriter.cpp
--- a/src/detail/writer/zipwriter.cpp	Tue Jan 04 12:42:06 2011 -0800
+++ b/src/detail/writer/zipwriter.cpp	Tue Jan 04 15:39:40 2011 -0800
@@ -106,14 +106,31 @@
 
     if (m_zipper==NULL)
     {
-        m_zipper = new LASzipper();
+        try
+        {
+            m_zipper = new LASzipper();
+        }
+        catch(...)
+        {
+            throw liblas_error("Error opening compression engine (1)");
+        }
 
         PointFormatName format = m_header->GetDataFormatId();
         m_zipPoint = new ZipPoint(format);
 
-        unsigned int stat = m_zipper->open(m_ofs, m_zipPoint->m_num_items, m_zipPoint->m_items, LASzip::COMPRESSION_DEFAULT);
+        unsigned int stat = 1;
+        try
+        {
+            stat = m_zipper->open(m_ofs, m_zipPoint->m_num_items, m_zipPoint->m_items, LASzip::COMPRESSION_DEFAULT);
+        }
+        catch(...)
+        {
+            throw liblas_error("Error opening compression engine (3)");
+        }
         if (stat != 0)
-            throw liblas_error("Error opening compression engine");
+        {
+            throw liblas_error("Error opening compression engine (2)");
+        }
     }
 
     const std::vector<boost::uint8_t>& v = point.GetData();
@@ -123,9 +140,19 @@
         //printf("%d %d\n", v[i], i);
     }
 
-    bool ok = m_zipper->write(m_zipPoint->m_lz_point);
+    bool ok = false;
+    try
+    {
+        ok = m_zipper->write(m_zipPoint->m_lz_point);
+    }
+    catch(...)
+    {
+        throw liblas_error("Error writing compressed point data (1)");
+    }
     if (!ok)
-        throw liblas_error("Error writing compressed point data");
+    {
+        throw liblas_error("Error writing compressed point data (2)");
+    }
 
     ++m_pointCount;
 
@@ -139,10 +166,9 @@
     try
     {
         UpdatePointCount(0);
-        
     } catch (std::runtime_error const&)
     {
-        
+        // ignore?
     }
 
     delete m_zipper;


More information about the Liblas-commits mailing list