mirror of
https://github.com/Unidata/netcdf-cxx4.git
synced 2025-02-17 18:59:31 +08:00
NcException: changed member variables to std::string*
This commit is contained in:
parent
a770fb3509
commit
127ff36095
@ -7,17 +7,25 @@ using namespace netCDF::exceptions;
|
||||
|
||||
// Default object thrown if a netCDF exception is encountered.
|
||||
NcException::NcException(const string& exceptionNameIn,const string& complaintIn,const char* fileNameIn,int lineNumberIn)
|
||||
:exceptionName(exceptionNameIn), complaint(complaintIn),fileName(fileNameIn), lineNumber(lineNumberIn)
|
||||
{}
|
||||
: what_msg(nullptr)
|
||||
{
|
||||
try{
|
||||
std::ostringstream oss;
|
||||
oss << lineNumberIn;
|
||||
what_msg = new std::string(exceptionNameIn+": "+complaintIn+"\nfile: "+fileNameIn+" line:"+oss.str());
|
||||
}catch(...){
|
||||
what_msg = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
NcException::~NcException()throw() {
|
||||
delete what_msg;
|
||||
}
|
||||
|
||||
NcException::~NcException()throw() {}
|
||||
|
||||
const char* NcException::what() const throw()
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << lineNumber;
|
||||
string message(exceptionName+": "+complaint+"\nfile: "+fileName+" line:"+oss.str());
|
||||
return message.c_str();
|
||||
return what_msg==nullptr ? "" : what_msg->c_str();
|
||||
}
|
||||
|
||||
|
||||
|
@ -27,8 +27,7 @@ namespace netCDF
|
||||
virtual ~NcException() throw();
|
||||
const char* what() const throw();
|
||||
private:
|
||||
std::string exceptionName, complaint, fileName;
|
||||
int lineNumber;
|
||||
std::string* what_msg;
|
||||
};
|
||||
|
||||
|
||||
|
@ -427,7 +427,7 @@ try
|
||||
if(var_4.isNull()) throw NcException("NcException","Error in test 28.1",__FILE__,__LINE__);
|
||||
struct3 dummyStruct3[2];
|
||||
var_4.getVar(dummyStruct3);
|
||||
|
||||
|
||||
if(dummyStruct3[1].mem1 != 1) throw NcException("NcException","Error in test 28.2",__FILE__,__LINE__);
|
||||
if(dummyStruct3[1].mem2 != -1.23456) throw NcException("NcException","Error in test 28.3",__FILE__,__LINE__);
|
||||
if(dummyStruct3[1].mem3[0] != 1) throw NcException("NcException","Error in test 28.4",__FILE__,__LINE__);
|
||||
@ -559,6 +559,6 @@ try
|
||||
catch (NcException& e)
|
||||
{
|
||||
cout << "unknown error"<<endl;
|
||||
e.what();
|
||||
cout << e.what();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user