Check if mesh file exists before loading

Also derive NgException from std::exception to print the error message
in Python / on the command line.
This commit is contained in:
Matthias Hochsteger 2017-08-24 13:59:16 +02:00
parent a0485eece0
commit d4a2d4c87b
4 changed files with 12 additions and 5 deletions

View File

@ -13,7 +13,7 @@ namespace netgen
NgException :: NgException (const string & s)
: what(s)
: m_what(s)
{
;
}
@ -27,7 +27,7 @@ namespace netgen
/// append string to description
void NgException :: Append (const string & s)
{
what += s;
m_what += s;
}
}

View File

@ -11,10 +11,10 @@ namespace netgen
{
/// Base class for all ng exceptions
class NgException
class NgException : public std::exception
{
/// verbal description of exception
string what;
string m_what;
public:
///
DLL_HEADER NgException (const string & s);
@ -26,7 +26,8 @@ public:
// void Append (const char * s);
/// verbal description of exception
const string & What() const { return what; }
const string & What() const { return m_what; }
virtual const char* what() const noexcept override { return m_what.c_str(); }
};
}

View File

@ -118,6 +118,11 @@ void Ng_LoadMeshFromStream ( istream & input )
void Ng_LoadMesh (const char * filename)
{
{
auto infile = ifstream (filename);
if(!infile.good())
throw NgException(string("Error opening file ") + filename);
}
#ifdef PARALLEL
MPI_Comm_size(MPI_COMM_WORLD, &ntasks);
MPI_Comm_rank(MPI_COMM_WORLD, &id);

View File

@ -52,6 +52,7 @@ static Transformation<3> global_trafo(Vec<3> (0,0,0));
DLL_HEADER void ExportNetgenMeshing(py::module &m)
{
py::register_exception<NgException>(m, "NgException");
m.attr("_netgen_executable_started") = py::cast(netgen::netgen_executable_started);
string script;
const char ** hcp = ngscript;