[Liblas-commits] hg: install a GDAL error handler that respects --debug and and i...

liblas-commits at liblas.org liblas-commits at liblas.org
Fri Aug 27 11:58:27 EDT 2010


changeset e3275d58439e in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=e3275d58439e
summary: install a GDAL error handler that respects --debug and and issues messages to std::cout.  Properly catch Execute() exceptions and throw more relevant errors in those cases

diffstat:

 apps/las2oci.cpp  |  58 ++++++++++++++++++++++++++++++++++++++++++++++--------
 apps/oci_util.cpp |  49 +++++++++++++++++++++++++++------------------
 2 files changed, 78 insertions(+), 29 deletions(-)

diffs (180 lines):

diff -r c64eebfcf3bf -r e3275d58439e apps/las2oci.cpp
--- a/apps/las2oci.cpp	Fri Aug 27 10:36:15 2010 -0500
+++ b/apps/las2oci.cpp	Fri Aug 27 10:58:20 2010 -0500
@@ -19,14 +19,47 @@
 
 
 
+
+void OCIGDALDebugErrorHandler(CPLErr eErrClass, int err_no, const char *msg)
+{
+    ostringstream oss;
+    
+    if (eErrClass == CE_Failure || eErrClass == CE_Fatal) {
+        oss <<"GDAL Failure number=" << err_no << ": " << msg;
+        throw std::runtime_error(oss.str());
+    } else if (eErrClass == CE_Debug) {
+        std::cout <<"GDAL Debug: " << msg << std::endl;
+    } else {
+        return;
+    }
+}
+
 void OCIGDALErrorHandler(CPLErr eErrClass, int err_no, const char *msg)
 {
     ostringstream oss;
-    oss <<"GDAL Error: type=" << eErrClass << " no=" << err_no << ": " << msg;
-    throw std::runtime_error(oss.str());
+    
+    if (eErrClass == CE_Failure || eErrClass == CE_Fatal) {
+        oss <<"GDAL Failure number=" << err_no << ": " << msg;
+        throw std::runtime_error(oss.str());
+    } else {
+        return;
+    }
 }
 
 
+void SetGDALErrorHandler(bool debug)
+{
+    CPLPopErrorHandler();
+    if (verbose)
+        CPLPushErrorHandler(OCIGDALDebugErrorHandler);
+    else
+        CPLPushErrorHandler(OCIGDALErrorHandler);
+
+}
+
+
+
+
 
 
 
@@ -260,9 +293,13 @@
     SetOrdinates(statement, sdo_ordinates, result.GetBounds());
     statement->Bind(&sdo_ordinates, connection->GetOrdinateType());
     
-    if (statement->Execute() == false) {
+    try {
+        statement->Execute();
+    } catch (std::runtime_error const& e) {
         delete statement;
-        return false;
+        ostringstream oss;
+        oss << "Failed to insert block # into '" << tableName << "' table. Does the table exist? "  << std::endl << e.what() << std::endl;
+        throw std::runtime_error(oss.str());
     }
     
     delete statement; statement = 0;
@@ -553,11 +590,12 @@
         statement->Bind((char*)&(header_data[0]),(long)header_data.size());
     
     }
-    if (statement->Execute() == false) {
-
-        std::cout << "statement execution failed "  << CPLGetLastErrorMsg() << std::endl;
-        delete statement;
-        return 0;
+    try {
+        statement->Execute();
+    } catch (std::runtime_error const& e) {
+        ostringstream oss;
+        oss << "Failed at creating Point Cloud entry into " << pcTableName << " table. Does the table exist? "  << e.what();
+        throw std::runtime_error(oss.str());
     }
     output = pc_id;
 
@@ -1023,6 +1061,8 @@
                 std::cout << "Caching entire file... " << std::endl;
         }
 
+        SetGDALErrorHandler(debug);
+
         filters = GetFilters(vm, verbose);
         
         // Transforms alter our header as well.  Setting scales, offsets, etc.
diff -r c64eebfcf3bf -r e3275d58439e apps/oci_util.cpp
--- a/apps/oci_util.cpp	Fri Aug 27 10:36:15 2010 -0500
+++ b/apps/oci_util.cpp	Fri Aug 27 10:58:20 2010 -0500
@@ -59,11 +59,13 @@
     
     statement = connection->CreateStatement(oss.str().c_str());
     
-    if (statement->Execute() == false) {
-        
-        std::cout << "statement execution failed "  << CPLGetLastErrorMsg() << std::endl;
+    try {
+        statement->Execute();
+    } catch (std::runtime_error const& e) {
         delete statement;
-        return 0;
+        std::ostringstream oss;
+        oss << "Failed to Enable tracing "  << std::endl << e.what() << std::endl;
+        throw std::runtime_error(oss.str());
     }    
     
     return true;
@@ -84,12 +86,15 @@
     
     statement->Bind(p_srid);
     statement->Define(kind);    
-    if (statement->Execute() == false) {
-        
-        std::cout << "statement execution failed "  << CPLGetLastErrorMsg() << std::endl;
+    
+    try {
+        statement->Execute();
+    } catch (std::runtime_error const& e) {
         delete statement;
-        return false;
-    }
+        std::ostringstream oss;
+        oss << "Failed to fetch geographicness of srid " << srid << std::endl << e.what() << std::endl;
+        throw std::runtime_error(oss.str());
+    }  
     
     if (compare_no_case(kind, "GEOGRAPHIC2D",12) == 0) {
         delete statement;
@@ -115,13 +120,14 @@
     OWStatement* statement = 0;
     statement = connection->CreateStatement(command.str().c_str());
     
-    if (statement->Execute() == false) {
-        
-        std::cout << "statement execution failed "  << CPLGetLastErrorMsg() << std::endl;
+    try {
+        statement->Execute();
+    } catch (std::runtime_error const& e) {
         delete statement;
-        return 0;
-    }
-    
+        std::ostringstream oss;
+        oss << "Failed to run SQL:" << command.str() << std::endl << e.what() << std::endl;
+        throw std::runtime_error(oss.str());
+    }      
     return statement;    
 }
 
@@ -181,12 +187,15 @@
     statement = connection->CreateStatement(oss.str().c_str());
     statement->Define(szTable);
     
-    if (statement->Execute() == false) {
-        
-        std::cout << "statement execution failed "  << CPLGetLastErrorMsg() << std::endl;
+    try {
+        statement->Execute();
+    } catch (std::runtime_error const& e) {
         delete statement;
-        return false;
-    }
+        std::ostringstream oss;
+        oss << "Failed select if block table "<< tableName << " exists.  Do you have rights to select?"  
+            << std::endl << e.what() << std::endl;
+        throw std::runtime_error(oss.str());
+    }  
     
     return true;
         


More information about the Liblas-commits mailing list