Error message on file open

Added optional error string parameter to openFile(). Made sure that
exceptions are handled. Returning false on file open error.
This commit is contained in:
Stein Dale
2015-05-06 13:22:09 +02:00
parent 3bbe7ec2dd
commit 5a3603bf43
3 changed files with 19 additions and 6 deletions

View File

@@ -41,7 +41,7 @@ public:
RifGeoMechReaderInterface();
virtual ~RifGeoMechReaderInterface();
virtual bool openFile(const std::string& fileName) = 0;
virtual bool openFile(const std::string& fileName, std::string* errorMessage = 0) = 0;
virtual bool readFemParts(RigFemPartCollection* geoMechCase) = 0;
virtual std::vector<std::string> stepNames() = 0;

View File

@@ -33,6 +33,7 @@
#include <map>
#include <iostream>
#include <limits>
#include <sstream>
std::map<std::string, RigElementType> initFemTypeMap()
@@ -105,7 +106,7 @@ void RifOdbReader::close()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RifOdbReader::openFile(const std::string& fileName)
bool RifOdbReader::openFile(const std::string& fileName, std::string* errorMessage)
{
close();
CVF_ASSERT(m_odb == NULL);
@@ -124,13 +125,25 @@ bool RifOdbReader::openFile(const std::string& fileName)
catch (const nex_Exception& nex)
{
fprintf(stderr, "%s\n", nex.UserReport().CStr());
fprintf(stderr, "ODB Application exited with error(s)\n");
if (errorMessage)
{
*errorMessage = nex.UserReport().CStr();
}
return false;
}
catch (...)
{
fprintf(stderr, "ODB Application exited with error(s)\n");
if (errorMessage)
{
std::stringstream errStr;
errStr << "Unable to open file '" << fileName << "'.";
*errorMessage = errStr.str();
}
return false;
}
return true;

View File

@@ -42,7 +42,7 @@ public:
RifOdbReader();
virtual ~RifOdbReader();
virtual bool openFile(const std::string& fileName);
virtual bool openFile(const std::string& fileName, std::string* errorMessage = 0);
virtual bool readFemParts(RigFemPartCollection* geoMechCase);
virtual std::vector<std::string> stepNames();