mirror of
https://github.com/NGSolve/netgen.git
synced 2025-01-12 22:20:35 +05:00
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:
parent
a0485eece0
commit
d4a2d4c87b
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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(); }
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user