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);
}
if (casterCh[0] == '\0')
{
try
{
ptDataAccessor = (uint64_t) AF->createAccessor(filename, filemode, size,
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)
{

View File

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

View File

@ -71,10 +71,11 @@ GDALAccessor::openFile (string filename, string accessMode, GDALDataset ** fd)
std::cout << "GDAL open (R): " << filename << std::endl;
(*fd) = (GDALDataset *) GDALOpenShared (filename.c_str (), GA_ReadOnly);
if ((*fd) == NULL)
{
{
cout << "Error. Cannot open the file " << filename << " in "
<< accessMode << " mode." << endl;
ERR_MESSAGE
throw runtime_error("GDAL file open error.");
// ERR_MESSAGE
;
}
}