(#515) Handling exceptions from NRLib

Returning error message string picked from exception when trying to read
a file, if any.
This commit is contained in:
Pål Hagen 2015-09-24 10:06:57 +02:00
parent 5d18209e26
commit f15c9973c9
2 changed files with 27 additions and 5 deletions

View File

@ -25,6 +25,8 @@
#include <QString> #include <QString>
#include <QFileInfo> #include <QFileInfo>
#include <exception>
#define RIG_WELL_FOOTPERMETER 3.2808399 #define RIG_WELL_FOOTPERMETER 3.2808399
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -48,15 +50,35 @@ RigWellLogFile::~RigWellLogFile()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
bool RigWellLogFile::open(const QString& fileName) bool RigWellLogFile::open(const QString& fileName, QString* errorMessage)
{ {
close(); close();
int wellFormat = NRLib::Well::LAS; int wellFormat = NRLib::Well::LAS;
NRLib::Well* well = NRLib::Well::ReadWell(fileName.toStdString(), wellFormat); NRLib::Well* well = NULL;
if (!well)
try
{ {
// TODO: Error handling int wellFormat = NRLib::Well::LAS;
well = NRLib::Well::ReadWell(fileName.toStdString(), wellFormat);
if (!well)
{
return false;
}
}
catch (std::exception& e)
{
if (well)
{
delete well;
}
if (e.what())
{
CVF_ASSERT(errorMessage);
*errorMessage = e.what();
}
return false; return false;
} }

View File

@ -40,7 +40,7 @@ public:
RigWellLogFile(); RigWellLogFile();
virtual ~RigWellLogFile(); virtual ~RigWellLogFile();
bool open(const QString& fileName); bool open(const QString& fileName, QString* errorMessage);
QString wellName() const; QString wellName() const;
QStringList wellLogChannelNames() const; QStringList wellLogChannelNames() const;