diff --git a/libsrc/general/ngexception.cpp b/libsrc/general/ngexception.cpp index 2496f6b3..6bcd2cc9 100644 --- a/libsrc/general/ngexception.cpp +++ b/libsrc/general/ngexception.cpp @@ -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; } } diff --git a/libsrc/general/ngexception.hpp b/libsrc/general/ngexception.hpp index 70dc0a4a..6e06498c 100644 --- a/libsrc/general/ngexception.hpp +++ b/libsrc/general/ngexception.hpp @@ -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(); } }; } diff --git a/libsrc/interface/nginterface.cpp b/libsrc/interface/nginterface.cpp index 39ddacd3..edce3398 100644 --- a/libsrc/interface/nginterface.cpp +++ b/libsrc/interface/nginterface.cpp @@ -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); diff --git a/libsrc/meshing/python_mesh.cpp b/libsrc/meshing/python_mesh.cpp index aaed8073..5db83ed1 100644 --- a/libsrc/meshing/python_mesh.cpp +++ b/libsrc/meshing/python_mesh.cpp @@ -52,6 +52,7 @@ static Transformation<3> global_trafo(Vec<3> (0,0,0)); DLL_HEADER void ExportNetgenMeshing(py::module &m) { + py::register_exception(m, "NgException"); m.attr("_netgen_executable_started") = py::cast(netgen::netgen_executable_started); string script; const char ** hcp = ngscript;