mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
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:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user