send better error message in c++, pass along in py

LT1AB
scott 2021-07-07 08:19:30 -05:00
parent 48b513fc42
commit 99d478f87e
2 changed files with 14 additions and 15 deletions

View File

@ -143,8 +143,7 @@ createAccessor_C(PyObject* self, PyObject* args)
} }
catch(const std::exception& e) catch(const std::exception& e)
{ {
std::cerr << e.what() << '\n'; PyErr_SetString(PyExc_OSError, e.what());
PyErr_SetString(PyExc_OSError, "Failed to created DataAccessor.");
return NULL; return NULL;
} }

View File

@ -69,22 +69,22 @@ GDALAccessor::openFile (string filename, string accessMode, GDALDataset ** fd)
if (accessMode == "read" || accessMode == "READ") if (accessMode == "read" || accessMode == "READ")
{ {
std::cout << "GDAL open (R): " << filename << std::endl; std::cout << "GDAL open (R): " << filename << std::endl;
(*fd) = (GDALDataset *) GDALOpenShared (filename.c_str (), GA_ReadOnly); (*fd) = (GDALDataset *) GDALOpenShared (filename.c_str (), GA_ReadOnly);
if ((*fd) == NULL) if ((*fd) == NULL)
{ {
cout << "Error. Cannot open the file " << filename << " in " string errMsg = "Cannot open the file " + filename + " in "
<< accessMode << " mode." << endl; + accessMode + " mode.";
throw runtime_error("GDAL file open error."); throw runtime_error(errMsg);
// ERR_MESSAGE // ERR_MESSAGE
; // ;
} }
} }
else else
{ {
cout << "Error. Only read mode is available and not " << accessMode string errMsg = "Error. Only read mode is available and not " + accessMode + " mode.";
<< " mode." << endl; throw runtime_error(errMsg);
ERR_MESSAGE // ERR_MESSAGE
; // ;
} }
} }