throw exception from c++ GdalAccessor instead of exit(1)
Leads to an OSError being thrown instead of shutting down the whole programLT1AB
parent
3928c3bdb7
commit
48b513fc42
|
@ -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)
|
||||||
{
|
{
|
||||||
|
|
|
@ -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"
|
||||||
|
|
|
@ -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
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue