throw exception from c++ GdalAccessor instead of exit(1)

Leads to an OSError being thrown instead of shutting down the whole program
LT1AB
scott 2021-07-06 22:07:00 -05:00
parent 3928c3bdb7
commit 48b513fc42
3 changed files with 14 additions and 2 deletions

View File

@ -135,9 +135,19 @@ createAccessor_C(PyObject* self, PyObject* args)
exit(1); exit(1);
} }
if (casterCh[0] == '\0') if (casterCh[0] == '\0')
{
try
{ {
ptDataAccessor = (uint64_t) AF->createAccessor(filename, filemode, size, ptDataAccessor = (uint64_t) AF->createAccessor(filename, filemode, size,
bands, width, scheme); bands, width, scheme);
}
catch(const std::exception& e)
{
std::cerr << e.what() << '\n';
PyErr_SetString(PyExc_OSError, "Failed to created DataAccessor.");
return NULL;
}
} }
else if (casterCh[0] != '\0' && PyDict_Size(dict) == 0) else if (casterCh[0] != '\0' && PyDict_Size(dict) == 0)
{ {

View File

@ -9,6 +9,7 @@
#endif #endif
#include <iostream> #include <iostream>
#include <stdexcept>
#include "InterleavedBase.h" #include "InterleavedBase.h"
#include <stdint.h> #include <stdint.h>
#include "gdal_priv.h" #include "gdal_priv.h"

View File

@ -74,7 +74,8 @@ GDALAccessor::openFile (string filename, string accessMode, GDALDataset ** fd)
{ {
cout << "Error. Cannot open the file " << filename << " in " cout << "Error. Cannot open the file " << filename << " in "
<< accessMode << " mode." << endl; << accessMode << " mode." << endl;
ERR_MESSAGE throw runtime_error("GDAL file open error.");
// ERR_MESSAGE
; ;
} }
} }