Merge branch 'check_file_exists' into 'master'

Check if mesh file exists before loading

See merge request !59
This commit is contained in:
Joachim Schöberl 2017-08-24 15:00:50 +02:00
commit eccccfea62
4 changed files with 12 additions and 5 deletions

View File

@ -13,7 +13,7 @@ namespace netgen
NgException :: NgException (const string & s) NgException :: NgException (const string & s)
: what(s) : m_what(s)
{ {
; ;
} }
@ -27,7 +27,7 @@ namespace netgen
/// append string to description /// append string to description
void NgException :: Append (const string & s) 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 /// Base class for all ng exceptions
class NgException class NgException : public std::exception
{ {
/// verbal description of exception /// verbal description of exception
string what; string m_what;
public: public:
/// ///
DLL_HEADER NgException (const string & s); DLL_HEADER NgException (const string & s);
@ -26,7 +26,8 @@ public:
// void Append (const char * s); // void Append (const char * s);
/// verbal description of exception /// 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) void Ng_LoadMesh (const char * filename)
{ {
{
auto infile = ifstream (filename);
if(!infile.good())
throw NgException(string("Error opening file ") + filename);
}
#ifdef PARALLEL #ifdef PARALLEL
MPI_Comm_size(MPI_COMM_WORLD, &ntasks); MPI_Comm_size(MPI_COMM_WORLD, &ntasks);
MPI_Comm_rank(MPI_COMM_WORLD, &id); 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) DLL_HEADER void ExportNetgenMeshing(py::module &m)
{ {
py::register_exception<NgException>(m, "NgException");
m.attr("_netgen_executable_started") = py::cast(netgen::netgen_executable_started); m.attr("_netgen_executable_started") = py::cast(netgen::netgen_executable_started);
string script; string script;
const char ** hcp = ngscript; const char ** hcp = ngscript;