[Liblas-commits] hg: add some custom exceptions

liblas-commits at liblas.org liblas-commits at liblas.org
Fri Dec 24 16:09:50 EST 2010


details:   http://hg.liblas.orghg/rev/46fdecf6b01c
changeset: 2649:46fdecf6b01c
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Fri Dec 24 13:09:47 2010 -0800
description:
add some custom exceptions

diffstat:

 apps/las2las.cpp                |   4 ++--
 include/liblas/exception.hpp    |  17 +++++++++++++++++
 src/detail/reader/zipreader.cpp |  12 ++++++------
 src/detail/writer/zipwriter.cpp |   6 +++---
 src/factory.cpp                 |   4 ++--
 5 files changed, 30 insertions(+), 13 deletions(-)

diffs (153 lines):

diff -r c5f71ed9f6fc -r 46fdecf6b01c apps/las2las.cpp
--- a/apps/las2las.cpp	Fri Dec 24 12:51:59 2010 -0800
+++ b/apps/las2las.cpp	Fri Dec 24 13:09:47 2010 -0800
@@ -334,12 +334,12 @@
 #ifdef HAVE_LASZIP
             header.SetCompressed(true);
 #else
-            throw std::runtime_error("Compression support not enabled in liblas configuration");
+            throw configuration_error("Compression support not enabled in liblas configuration");
 #endif
             break;
         case WriterFactory::FileType_Unknown:
         default:
-            throw std::runtime_error("Unknown output file type");
+            throw liblas_error("Unknown output file type");
             break;
         }
 
diff -r c5f71ed9f6fc -r 46fdecf6b01c include/liblas/exception.hpp
--- a/include/liblas/exception.hpp	Fri Dec 24 12:51:59 2010 -0800
+++ b/include/liblas/exception.hpp	Fri Dec 24 13:09:47 2010 -0800
@@ -98,6 +98,23 @@
     {}
 };
 
+// use this for attempts to use a feature not compiled in, e.g. laszip or gdal
+class configuration_error : public liblas_error
+{
+public:
+    configuration_error(std::string const& msg)
+        : liblas_error(msg)
+    {}
+};
+
+// use this for code still under development
+class not_yet_implemented : public liblas_error
+{
+public:
+    not_yet_implemented(std::string const& msg)
+        : liblas_error(msg)
+    {}
+};
 
 } // namespace liblas
 
diff -r c5f71ed9f6fc -r 46fdecf6b01c src/detail/reader/zipreader.cpp
--- a/src/detail/reader/zipreader.cpp	Fri Dec 24 12:51:59 2010 -0800
+++ b/src/detail/reader/zipreader.cpp	Fri Dec 24 13:09:47 2010 -0800
@@ -120,7 +120,7 @@
 
         unsigned int stat = m_unzipper->open(m_ifs, m_num_items, m_items, LASZIP_COMPRESSION_DEFAULT);
         if (stat != 0)
-            throw std::runtime_error("Failed to open laszip decompression engine"); 
+            throw liblas_error("Failed to open laszip decompression engine"); 
     }
 
     return;
@@ -170,7 +170,7 @@
         break;
 
     default:
-        throw std::out_of_range("Bad point format in header"); 
+        throw liblas_error("Bad point format in header"); 
     }
 
     // construct the object that will hold a laszip point
@@ -239,7 +239,7 @@
     m_header = m_header_reader->GetHeader();
 
     if (!m_header->Compressed())
-        throw std::runtime_error("Internal error: compressed reader encountered uncompressed header"); 
+        throw liblas_error("Internal error: compressed reader encountered uncompressed header"); 
 
     m_point->SetHeaderPtr(m_header);
 
@@ -259,7 +259,7 @@
 
     bool ok = m_unzipper->read(m_lz_point);
     if (!ok)
-        throw std::runtime_error("Error reading compressed point data");
+        throw liblas_error("Error reading compressed point data");
 
     std::vector<boost::uint8_t> v(m_lz_point_size);
     for (unsigned int i=0; i<m_lz_point_size; i++)
@@ -329,7 +329,7 @@
 
     if (n!=0)
     {
-        throw std::runtime_error("not yet implemented");
+        throw not_yet_implemented("not yet implemented");
     }
 
     std::streamsize const pos = /*(static_cast<std::streamsize>(n) * m_header->GetDataRecordLength()) +*/ m_header->GetDataOffset();    
@@ -360,7 +360,7 @@
 
     if (n!=0)
     {
-        throw std::runtime_error("not yet implemented");
+        throw not_yet_implemented("not yet implemented");
     }
 
     std::streamsize pos = /*(static_cast<std::streamsize>(n) * m_header->GetDataRecordLength()) +*/ m_header->GetDataOffset();    
diff -r c5f71ed9f6fc -r 46fdecf6b01c src/detail/writer/zipwriter.cpp
--- a/src/detail/writer/zipwriter.cpp	Fri Dec 24 12:51:59 2010 -0800
+++ b/src/detail/writer/zipwriter.cpp	Fri Dec 24 13:09:47 2010 -0800
@@ -134,7 +134,7 @@
         break;
 
     default:
-        throw std::out_of_range("Bad point format in header"); 
+        throw liblas_error("Bad point format in header"); 
     }
 
     // construct the object that will hold a laszip point
@@ -173,7 +173,7 @@
 
         unsigned int stat = m_zipper->open(m_ofs, m_num_items, m_items, LASZIP_COMPRESSION_DEFAULT);
         if (stat != 0)
-            throw std::runtime_error("Error opening compression engine");
+            throw liblas_error("Error opening compression engine");
     }
 
     const std::vector<boost::uint8_t>& v = point.GetData();
@@ -185,7 +185,7 @@
 
     bool ok = m_zipper->write(m_lz_point);
     if (!ok)
-        throw std::runtime_error("Error writing compressed point data");
+        throw liblas_error("Error writing compressed point data");
 
     return;
 }
diff -r c5f71ed9f6fc -r 46fdecf6b01c src/factory.cpp
--- a/src/factory.cpp	Fri Dec 24 12:51:59 2010 -0800
+++ b/src/factory.cpp	Fri Dec 24 13:09:47 2010 -0800
@@ -89,7 +89,7 @@
         ReaderIPtr r = ReaderIPtr(new detail::ZipReaderImpl(stream) );
         return liblas::Reader(r);
 #else
-        throw std::runtime_error("Compression support not enabled in liblas configuration");
+        throw configuration_error("Compression support not enabled in liblas configuration");
 #endif
     }
 
@@ -114,7 +114,7 @@
         return w;
 #else
     boost::ignore_unused_variable_warning(stream);
-    throw std::runtime_error("Compression support not enabled in libLAS configuration");
+    throw configuration_error("Compression support not enabled in libLAS configuration");
 #endif
     }
 


More information about the Liblas-commits mailing list