Skip to content
Snippets Groups Projects
Commit c942caed authored by Giovanni Bussi's avatar Giovanni Bussi
Browse files

Allow code to be passed in error handler.

Not used yet, but we can use it to throw different exception types.
parent f87e9de6
No related branches found
No related tags found
No related merge requests found
......@@ -102,7 +102,7 @@ private:
/// Should only be called from \ref plumed_plumedmain_cmd().
typedef struct {
void* ptr;
void(*handler)(void* ptr,const char*);
void(*handler)(void* ptr,int code,const char*);
} plumed_error_handler;
plumed_error_handler error_handler= {NULL,NULL};
......@@ -392,7 +392,7 @@ public:
/// Call error handler.
/// Should only be called from \ref plumed_plumedmain_cmd().
/// If the error handler was not set, returns false.
bool callErrorHandler(const char* msg)const;
bool callErrorHandler(int code,const char* msg)const;
};
/////
......@@ -464,9 +464,9 @@ void PlumedMain::setEndPlumed() {
}
inline
bool PlumedMain::callErrorHandler(const char* msg)const {
bool PlumedMain::callErrorHandler(int code,const char* msg)const {
if(error_handler.handler) {
error_handler.handler(error_handler.ptr,msg);
error_handler.handler(error_handler.ptr,code,msg);
return true;
} else return false;
}
......
......@@ -44,7 +44,7 @@ extern "C" void plumed_plumedmain_cmd(void*plumed,const char*key,const void*val)
// if a error_handler was provided, we use it to manage this exception.
// this allows an exception to be catched also if the MD code
// was linked against a different C++ library
if(!p->callErrorHandler(e.what())) throw;
if(!p->callErrorHandler(2,e.what())) throw;
}
}
......
......@@ -521,7 +521,7 @@ typedef struct {
typedef struct {
void* ptr;
void(*handler)(void* ptr,const char*);
void(*handler)(void* ptr,int code,const char*);
} plumed_error_handler;
/** \relates plumed
......@@ -958,8 +958,9 @@ class Plumed {
/**
Error handler installed to rethrow exceptions.
*/
static void cxx_error_handler(void*ptr, const char*what) {
static void cxx_error_handler(void*ptr, int code, const char*what) {
(void) ptr;
(void) code;
throw Plumed::Exception(what);
}
......@@ -2094,9 +2095,9 @@ void plumed_cmd(plumed p,const char*key,const void*val) {
if(!pimpl->p) {
if(pimpl->error_handler.handler) {
if(pimpl->used_plumed_kernel) {
pimpl->error_handler.handler(pimpl->error_handler.ptr,"You are trying to use plumed, but it is not available.\nCheck your PLUMED_KERNEL environment variable.");
pimpl->error_handler.handler(pimpl->error_handler.ptr,1,"You are trying to use plumed, but it is not available.\nCheck your PLUMED_KERNEL environment variable.");
} else {
pimpl->error_handler.handler(pimpl->error_handler.ptr,"You are trying to use plumed, but it is not available.");
pimpl->error_handler.handler(pimpl->error_handler.ptr,1,"You are trying to use plumed, but it is not available.");
}
} else {
__PLUMED_FPRINTF(stderr,"+++ ERROR: You are trying to use plumed, but it is not available. +++\n");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment