Merge pull request #315 from scottstanie/main

throw exception from c++ instead of exit(1)
LT1AB
Ryan Burns 2021-08-11 12:25:13 -07:00 committed by GitHub
commit 10e03b6e01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 20 deletions

View File

@ -136,8 +136,17 @@ createAccessor_C(PyObject* self, PyObject* args)
}
if (casterCh[0] == '\0')
{
ptDataAccessor = (uint64_t) AF->createAccessor(filename, filemode, size,
bands, width, scheme);
try
{
ptDataAccessor = (uint64_t) AF->createAccessor(filename, filemode, size,
bands, width, scheme);
}
catch(const std::exception& e)
{
PyErr_SetString(PyExc_OSError, e.what());
return NULL;
}
}
else if (casterCh[0] != '\0' && PyDict_Size(dict) == 0)
{

View File

@ -10,6 +10,7 @@
#include <stdlib.h>
#include <string>
#include <stdexcept>
using namespace std;

View File

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

View File

@ -112,8 +112,8 @@ void InterleavedAccessor::openFile(string filename, string accessMode, fstream
fd.open(filename.c_str(), ios_base::in);
if(fd.fail())
{
cout << "Error. Cannot open the file " << filename << " in " << accessMode << " mode." <<endl;
ERR_MESSAGE;
string errMsg = "Cannot open the file " + filename + " in " + accessMode + " mode.";
throw runtime_error(errMsg);
}
}
@ -139,13 +139,13 @@ void InterleavedAccessor::openFile(string filename, string accessMode, fstream
}
else
{
cout << "Error. Unrecognized open mode " << accessMode << " for file " << filename << endl;
ERR_MESSAGE;
string errMsg = "Unrecognized open mode " + accessMode + " for file " + filename;
throw runtime_error(errMsg);
}
if(!fd.good())
{
cout << "Cannot open file " << filename << endl;
ERR_MESSAGE;
string errMsg = "Cannot open file " + filename;
throw runtime_error(errMsg);
}
}
void InterleavedAccessor::getStream(char * dataLine, int & numEl)