From e79c83ac4289fd45019f137fa2a50fb409d98763 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@uliege.be>
Date: Sat, 4 Jul 2020 20:55:28 +0200
Subject: [PATCH] api errors in C++, Python and Julia now throw strings with
 the last error message instead of an unhelpful integer.

The new api function getLastError() can also be used to retrieve this error; useful e.g. in the C api.
---
 Common/GmshMessage.cpp |   11 +-
 Common/GmshMessage.h   |    3 +-
 Common/gmsh.cpp        | 1302 +++++++++++++++++++------------------
 api/GenApi.py          |   38 +-
 api/gen.py             |    3 +
 api/gmsh.h             |    5 +
 api/gmsh.h_cwrap       |  589 ++++++++---------
 api/gmsh.jl            |  820 ++++++++++++------------
 api/gmsh.py            | 1378 ++++++++++++----------------------------
 api/gmshc.cpp          | 1145 ++++++++++++++++-----------------
 api/gmshc.h            |    4 +
 doc/texinfo/api.texi   |   12 +
 12 files changed, 2467 insertions(+), 2843 deletions(-)

diff --git a/Common/GmshMessage.cpp b/Common/GmshMessage.cpp
index cf98c98da6..ac086da531 100644
--- a/Common/GmshMessage.cpp
+++ b/Common/GmshMessage.cpp
@@ -69,6 +69,7 @@ int Msg::_errorCount = 0;
 int Msg::_atLeastOneErrorInRun = 0;
 std::string Msg::_firstWarning;
 std::string Msg::_firstError;
+std::string Msg::_lastError;
 GmshMessage *Msg::_callback = 0;
 std::string Msg::_commandLine;
 std::string Msg::_launchDate;
@@ -301,6 +302,11 @@ std::string Msg::GetFirstError()
   return _firstError;
 }
 
+std::string Msg::GetLastError()
+{
+  return _lastError;
+}
+
 void Msg::SetExecutableName(const std::string &name)
 {
   _execName.assign(name);
@@ -497,6 +503,8 @@ void Msg::Error(const char *fmt, ...)
   if(_logFile) fprintf(_logFile, "Error: %s\n", str);
   if(_callback) (*_callback)("Error", str);
   if(_client) _client->Error(str);
+  if(_firstError.empty()) _firstError = str;
+  _lastError = str;
 
 #if defined(HAVE_FLTK)
   if(FlGui::available()){
@@ -504,7 +512,6 @@ void Msg::Error(const char *fmt, ...)
     std::string tmp = std::string(CTX::instance()->guiColorScheme ? "@B72@." : "@C1@.")
       + "Error   : " + str;
     FlGui::instance()->addMessage(tmp.c_str());
-    if(_firstError.empty()) _firstError = str;
     FlGui::instance()->setLastStatus
       (CTX::instance()->guiColorScheme ? FL_DARK_RED : FL_RED);
   }
@@ -841,7 +848,7 @@ void Msg::PrintTimers()
 void Msg::ResetErrorCounter()
 {
   _warningCount = 0; _errorCount = 0;
-  _firstWarning.clear(); _firstError.clear();
+  _firstWarning.clear(); _firstError.clear(); _lastError.clear();
 #if defined(HAVE_FLTK)
   if(FlGui::available()) FlGui::instance()->setLastStatus();
 #endif
diff --git a/Common/GmshMessage.h b/Common/GmshMessage.h
index bf28e53bcb..f6f83d5f1e 100644
--- a/Common/GmshMessage.h
+++ b/Common/GmshMessage.h
@@ -48,7 +48,7 @@ private:
   static double _startTime;
   // counters
   static int _warningCount, _errorCount, _atLeastOneErrorInRun;
-  static std::string _firstWarning, _firstError;
+  static std::string _firstWarning, _firstError, _lastError;
   // callback
   static GmshMessage *_callback;
   // command-line and startup time
@@ -117,6 +117,7 @@ public:
   static int GetErrorCount();
   static std::string GetFirstWarning();
   static std::string GetFirstError();
+  static std::string GetLastError();
   static double GetValue(const char *text, double defaultval);
   static std::string GetString(const char *text, const std::string &defaultval);
   static int GetAnswer(const char *question, int defaultval, const char *zero,
diff --git a/Common/gmsh.cpp b/Common/gmsh.cpp
index 2cbb282d62..d04bf7b827 100644
--- a/Common/gmsh.cpp
+++ b/Common/gmsh.cpp
@@ -97,7 +97,7 @@ static int _initialized = 0;
 static int _argc = 0;
 static char **_argv = 0;
 
-static bool _isInitialized()
+static bool _isInit()
 {
   if(!_initialized) {
     // make sure stuff gets printed out
@@ -112,6 +112,11 @@ static bool _isInitialized()
   return true;
 }
 
+static void _checkInit()
+{
+  if(!_isInit()) throw Msg::GetLastError();
+}
+
 // gmsh
 
 GMSH_API void gmsh::initialize(int argc, char **argv, bool readConfigFiles)
@@ -127,12 +132,13 @@ GMSH_API void gmsh::initialize(int argc, char **argv, bool readConfigFiles)
     for(int i = 0; i < argc; i++) _argv[i] = argv[i];
     return;
   }
-  throw -1;
+  Msg::Error("Something went wrong when initializing Gmsh");
+  throw Msg::GetLastError();
 }
 
 GMSH_API void gmsh::finalize()
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   if(GmshFinalize()) {
     _argc = 0;
     if(_argv) delete[] _argv;
@@ -141,35 +147,43 @@ GMSH_API void gmsh::finalize()
     return;
   }
   Msg::Error("Something went wrong when finalizing Gmsh");
-  throw 1;
+  throw Msg::GetLastError();
 }
 
 GMSH_API void gmsh::open(const std::string &fileName)
 {
-  if(!_isInitialized()) { throw -1; }
-  if(GmshOpenProject(fileName)) return;
-  throw 1;
+  _checkInit();
+  if(!GmshOpenProject(fileName)) {
+    Msg::Error("Could not open file '%s'", fileName.c_str());
+    throw Msg::GetLastError();
+  }
 }
 
 GMSH_API void gmsh::merge(const std::string &fileName)
 {
-  if(!_isInitialized()) { throw -1; }
-  if(GmshMergeFile(fileName)) return;
-  throw 1;
+  _checkInit();
+  if(!GmshMergeFile(fileName)) {
+    Msg::Error("Could not merge file '%s'", fileName.c_str());
+    throw Msg::GetLastError();
+  }
 }
 
 GMSH_API void gmsh::write(const std::string &fileName)
 {
-  if(!_isInitialized()) { throw -1; }
-  if(GmshWriteFile(fileName)) return;
-  throw 1;
+  _checkInit();
+  if(!GmshWriteFile(fileName)) {
+    Msg::Error("Could not write file '%s'", fileName.c_str());
+    throw Msg::GetLastError();
+  }
 }
 
 GMSH_API void gmsh::clear()
 {
-  if(!_isInitialized()) { throw -1; }
-  if(GmshClearProject()) return;
-  throw 1;
+  _checkInit();
+  if(!GmshClearProject()) {
+    Msg::Error("Could not clear project");
+    throw Msg::GetLastError();
+  }
 }
 
 // gmsh::option
@@ -177,62 +191,72 @@ GMSH_API void gmsh::clear()
 GMSH_API void gmsh::option::setNumber(const std::string &name,
                                       const double value)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   std::string c, n;
   int i;
   SplitOptionName(name, c, n, i);
-  if(GmshSetOption(c, n, value, i)) return;
-  throw 1;
+  if(!GmshSetOption(c, n, value, i)) {
+    Msg::Error("Could not set option '%s'", name.c_str());
+    throw Msg::GetLastError();
+  }
 }
 
 GMSH_API void gmsh::option::getNumber(const std::string &name, double &value)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   std::string c, n;
   int i;
   SplitOptionName(name, c, n, i);
-  if(GmshGetOption(c, n, value, i)) return;
-  throw 1;
+  if(!GmshGetOption(c, n, value, i)) {
+    Msg::Error("Could not get option '%s'", name.c_str());
+    throw Msg::GetLastError();
+  }
 }
 
 GMSH_API void gmsh::option::setString(const std::string &name,
                                       const std::string &value)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   std::string c, n;
   int i;
   SplitOptionName(name, c, n, i);
-  if(GmshSetOption(c, n, value, i)) return;
-  throw 1;
+  if(!GmshSetOption(c, n, value, i)) {
+    Msg::Error("Could not set option '%s'", name.c_str());
+    throw Msg::GetLastError();
+  }
 }
 
 GMSH_API void gmsh::option::getString(const std::string &name,
                                       std::string &value)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   std::string c, n;
   int i;
   SplitOptionName(name, c, n, i);
-  if(GmshGetOption(c, n, value, i)) return;
-  throw 1;
+  if(!GmshGetOption(c, n, value, i)) {
+    Msg::Error("Could not get option '%s'", name.c_str());
+    throw Msg::GetLastError();
+  }
 }
 
 GMSH_API void gmsh::option::setColor(const std::string &name, const int r,
                                      const int g, const int b, const int a)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   std::string c, n;
   int i;
   SplitOptionName(name, c, n, i);
   unsigned int value = CTX::instance()->packColor(r, g, b, a);
-  if(GmshSetOption(c, n, value, i)) return;
-  throw 1;
+  if(!GmshSetOption(c, n, value, i)) {
+    Msg::Error("Could not set option '%s'", name.c_str());
+    throw Msg::GetLastError();
+  }
 }
 
 GMSH_API void gmsh::option::getColor(const std::string &name, int &r, int &g,
                                      int &b, int &a)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   std::string c, n;
   int i;
   SplitOptionName(name, c, n, i);
@@ -242,46 +266,57 @@ GMSH_API void gmsh::option::getColor(const std::string &name, int &r, int &g,
     g = CTX::instance()->unpackGreen(value);
     b = CTX::instance()->unpackBlue(value);
     a = CTX::instance()->unpackAlpha(value);
-    return;
   }
-  throw 1;
+  else{
+    Msg::Error("Could not get option '%s'", name.c_str());
+    throw Msg::GetLastError();
+  }
 }
 
 // gmsh::model
 
 GMSH_API void gmsh::model::add(const std::string &name)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GModel *m = new GModel(name);
-  if(!m) { throw 1; }
+  if(!m) {
+    Msg::Error("Could not add model '%s'", name.c_str());
+    throw Msg::GetLastError();
+  }
 }
 
 GMSH_API void gmsh::model::remove()
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GModel *m = GModel::current();
-  if(!m) { throw 1; }
+  if(!m) {
+    Msg::Error("Could not remove current model");
+    throw Msg::GetLastError();
+  }
   delete m;
 }
 
 GMSH_API void gmsh::model::list(std::vector<std::string> &names)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   for(std::size_t i = 0; i < GModel::list.size(); i++)
     names.push_back(GModel::list[i]->getName());
 }
 
 GMSH_API void gmsh::model::getCurrent(std::string &name)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   name = GModel::current()->getName();
 }
 
 GMSH_API void gmsh::model::setCurrent(const std::string &name)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GModel *m = GModel::findByName(name);
-  if(!m) { throw 1; }
+  if(!m) {
+    Msg::Error("Could find model '%s'", name.c_str());
+    throw Msg::GetLastError();
+  }
   GModel::setCurrent(m);
   for(std::size_t i = 0; i < GModel::list.size(); i++)
     GModel::list[i]->setVisibility(0);
@@ -291,7 +326,7 @@ GMSH_API void gmsh::model::setCurrent(const std::string &name)
 
 GMSH_API void gmsh::model::getEntities(vectorpair &dimTags, const int dim)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   dimTags.clear();
   std::vector<GEntity *> entities;
   GModel::current()->getEntities(entities, dim);
@@ -303,20 +338,20 @@ GMSH_API void gmsh::model::getEntities(vectorpair &dimTags, const int dim)
 GMSH_API void gmsh::model::setEntityName(const int dim, const int tag,
                                          const std::string &name)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GModel::current()->setElementaryName(dim, tag, name);
 }
 
 GMSH_API void gmsh::model::getEntityName(const int dim, const int tag,
                                          std::string &name)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   name = GModel::current()->getElementaryName(dim, tag);
 }
 
 GMSH_API void gmsh::model::getPhysicalGroups(vectorpair &dimTags, const int dim)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   dimTags.clear();
   std::map<int, std::vector<GEntity *> > groups[4];
   GModel::current()->getPhysicalGroups(groups);
@@ -347,7 +382,7 @@ GMSH_API void gmsh::model::getEntitiesForPhysicalGroup(const int dim,
                                                        const int tag,
                                                        std::vector<int> &tags)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   tags.clear();
   std::map<int, std::vector<GEntity *> > groups;
   GModel::current()->getPhysicalGroups(dim, groups);
@@ -358,7 +393,7 @@ GMSH_API void gmsh::model::getEntitiesForPhysicalGroup(const int dim,
   }
   else {
     Msg::Error("Physical %s does not exist", _getEntityName(dim, tag).c_str());
-    throw 2;
+    throw Msg::GetLastError();
   }
 }
 
@@ -366,12 +401,12 @@ GMSH_API void
 gmsh::model::getPhysicalGroupsForEntity(const int dim, const int tag,
                                         std::vector<int> &physicalTags)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   physicalTags.clear();
   GEntity *ge = GModel::current()->getEntityByTag(dim, tag);
   if(!ge) {
     Msg::Error("%s does not exist", _getEntityName(dim, tag).c_str());
-    throw 2;
+    throw Msg::GetLastError();
   }
   std::vector<int> phy = ge->getPhysicalEntities();
   physicalTags.resize(phy.size());
@@ -388,7 +423,7 @@ GMSH_API int gmsh::model::addPhysicalGroup(const int dim,
   // physicals to GModel, we need to add the physicals in GEOInternals and
   // perform a hidden sync (which should not reset the mesh attributes of the
   // entities of they have already been created...).
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   int outTag = tag;
   if(outTag < 0) {
     outTag =
@@ -398,7 +433,8 @@ GMSH_API int gmsh::model::addPhysicalGroup(const int dim,
   }
   if(!GModel::current()->getGEOInternals()->modifyPhysicalGroup(dim, outTag, 0,
                                                                 tags)) {
-    throw 1;
+    Msg::Error("Could not add physical group");
+    throw Msg::GetLastError();
   }
   GModel::current()->getGEOInternals()->synchronize(GModel::current(), false);
   return outTag;
@@ -407,14 +443,14 @@ GMSH_API int gmsh::model::addPhysicalGroup(const int dim,
 GMSH_API void gmsh::model::setPhysicalName(const int dim, const int tag,
                                            const std::string &name)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GModel::current()->setPhysicalName(name, dim, tag);
 }
 
 GMSH_API void gmsh::model::getPhysicalName(const int dim, const int tag,
                                            std::string &name)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   name = GModel::current()->getPhysicalName(dim, tag);
 }
 
@@ -423,11 +459,12 @@ GMSH_API void gmsh::model::getBoundary(const vectorpair &dimTags,
                                        const bool combined, const bool oriented,
                                        const bool recursive)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   outDimTags.clear();
   if(!GModel::current()->getBoundaryTags(dimTags, outDimTags, combined,
                                          oriented, recursive)) {
-    throw 1;
+    Msg::Error("Could not get boundary");
+    throw Msg::GetLastError();
   }
 }
 
@@ -435,7 +472,7 @@ GMSH_API void gmsh::model::getEntitiesInBoundingBox(
   const double xmin, const double ymin, const double zmin, const double xmax,
   const double ymax, const double zmax, vectorpair &dimTags, const int dim)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   dimTags.clear();
   SBoundingBox3d box(xmin, ymin, zmin, xmax, ymax, zmax);
   std::vector<GEntity *> entities;
@@ -450,22 +487,28 @@ GMSH_API void gmsh::model::getBoundingBox(const int dim, const int tag,
                                           double &zmin, double &xmax,
                                           double &ymax, double &zmax)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 
   SBoundingBox3d box;
   if(dim < 0 && tag < 0) {
     box = GModel::current()->bounds();
-    if(box.empty()) { throw(3); }
+    if(box.empty()) {
+      Msg::Error("Empty bounding box");
+      throw Msg::GetLastError();
+    }
   }
   else {
     GEntity *ge = GModel::current()->getEntityByTag(dim, tag);
     if(!ge) {
       Msg::Error("%s does not exist", _getEntityName(dim, tag).c_str());
-      throw 2;
+      throw Msg::GetLastError();
     }
     box = ge->bounds();
   }
-  if(box.empty()) { throw(3); }
+  if(box.empty()) {
+    Msg::Error("Empty bounding box");
+    throw Msg::GetLastError();
+  }
   xmin = box.min().x();
   ymin = box.min().y();
   zmin = box.min().z();
@@ -476,7 +519,7 @@ GMSH_API void gmsh::model::getBoundingBox(const int dim, const int tag,
 
 GMSH_API int gmsh::model::getDimension()
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 
   return GModel::current()->getDim();
 }
@@ -484,7 +527,7 @@ GMSH_API int gmsh::model::getDimension()
 GMSH_API int gmsh::model::addDiscreteEntity(const int dim, const int tag,
                                             const std::vector<int> &boundary)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   int outTag = tag;
   if(outTag < 0) {
     outTag = GModel::current()->getMaxElementaryNumber(dim) + 1;
@@ -492,7 +535,7 @@ GMSH_API int gmsh::model::addDiscreteEntity(const int dim, const int tag,
   GEntity *e = GModel::current()->getEntityByTag(dim, outTag);
   if(e) {
     Msg::Error("%s already exists", _getEntityName(dim, outTag).c_str());
-    throw 2;
+    throw Msg::GetLastError();
   }
   switch(dim) {
   case 0: {
@@ -532,7 +575,6 @@ GMSH_API int gmsh::model::addDiscreteEntity(const int dim, const int tag,
     GModel::current()->add(gr);
     break;
   }
-  default: throw 2;
   }
   return outTag;
 }
@@ -540,19 +582,19 @@ GMSH_API int gmsh::model::addDiscreteEntity(const int dim, const int tag,
 GMSH_API void gmsh::model::removeEntities(const vectorpair &dimTags,
                                           const bool recursive)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GModel::current()->remove(dimTags, recursive);
 }
 
 GMSH_API void gmsh::model::removeEntityName(const std::string &name)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GModel::current()->removeElementaryName(name);
 }
 
 GMSH_API void gmsh::model::removePhysicalGroups(const vectorpair &dimTags)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   if(dimTags.empty()) {
     GModel::current()->getGEOInternals()->resetPhysicalGroups();
     GModel::current()->removePhysicalGroups();
@@ -570,18 +612,18 @@ GMSH_API void gmsh::model::removePhysicalGroups(const vectorpair &dimTags)
 
 GMSH_API void gmsh::model::removePhysicalName(const std::string &name)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GModel::current()->removePhysicalName(name);
 }
 
 GMSH_API void gmsh::model::getType(const int dim, const int tag,
                                    std::string &entityType)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GEntity *ge = GModel::current()->getEntityByTag(dim, tag);
   if(!ge) {
     Msg::Error("%s does not exist", _getEntityName(dim, tag).c_str());
-    throw 2;
+    throw Msg::GetLastError();
   }
   entityType = ge->getTypeString();
 }
@@ -589,13 +631,13 @@ GMSH_API void gmsh::model::getType(const int dim, const int tag,
 GMSH_API void gmsh::model::getParent(const int dim, const int tag,
                                      int &parentDim, int &parentTag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   parentDim = -1;
   parentTag = -1;
   GEntity *ge = GModel::current()->getEntityByTag(dim, tag);
   if(!ge) {
     Msg::Error("%s does not exist", _getEntityName(dim, tag).c_str());
-    throw 2;
+    throw Msg::GetLastError();
   }
   GEntity *parent = ge->getParentEntity();
   if(parent) {
@@ -607,12 +649,12 @@ GMSH_API void gmsh::model::getParent(const int dim, const int tag,
 GMSH_API void gmsh::model::getPartitions(const int dim, const int tag,
                                          std::vector<int> &partitions)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   partitions.clear();
   GEntity *ge = GModel::current()->getEntityByTag(dim, tag);
   if(!ge) {
     Msg::Error("%s does not exist", _getEntityName(dim, tag).c_str());
-    throw 2;
+    throw Msg::GetLastError();
   }
   std::vector<int> p;
   if(ge->geomType() == GEntity::PartitionPoint)
@@ -637,12 +679,12 @@ GMSH_API void gmsh::model::getValue(const int dim, const int tag,
                                     const std::vector<double> &parametricCoord,
                                     std::vector<double> &coord)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   coord.clear();
   GEntity *entity = GModel::current()->getEntityByTag(dim, tag);
   if(!entity) {
     Msg::Error("%s does not exist", _getEntityName(dim, tag).c_str());
-    throw 2;
+    throw Msg::GetLastError();
   }
   if(dim == 0) {
     coord.push_back(static_cast<GVertex *>(entity)->x());
@@ -676,12 +718,12 @@ gmsh::model::getDerivative(const int dim, const int tag,
                            const std::vector<double> &parametricCoord,
                            std::vector<double> &deriv)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   deriv.clear();
   GEntity *entity = GModel::current()->getEntityByTag(dim, tag);
   if(!entity) {
     Msg::Error("%s does not exist", _getEntityName(dim, tag).c_str());
-    throw 2;
+    throw Msg::GetLastError();
   }
   if(dim == 1) {
     GEdge *ge = static_cast<GEdge *>(entity);
@@ -713,12 +755,12 @@ gmsh::model::getCurvature(const int dim, const int tag,
                           const std::vector<double> &parametricCoord,
                           std::vector<double> &curvatures)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   curvatures.clear();
   GEntity *entity = GModel::current()->getEntityByTag(dim, tag);
   if(!entity) {
     Msg::Error("%s does not exist", _getEntityName(dim, tag).c_str());
-    throw 2;
+    throw Msg::GetLastError();
   }
   if(dim == 1) {
     GEdge *ge = static_cast<GEdge *>(entity);
@@ -740,11 +782,11 @@ GMSH_API void gmsh::model::getPrincipalCurvatures(
   std::vector<double> &curvaturesMax, std::vector<double> &curvaturesMin,
   std::vector<double> &directionsMax, std::vector<double> &directionsMin)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GFace *gf = GModel::current()->getFaceByTag(tag);
   if(!gf) {
     Msg::Error("%s does not exist", _getEntityName(2, tag).c_str());
-    throw 2;
+    throw Msg::GetLastError();
   }
   curvaturesMax.clear();
   curvaturesMin.clear();
@@ -771,11 +813,11 @@ GMSH_API void gmsh::model::getNormal(const int tag,
                                      const std::vector<double> &parametricCoord,
                                      std::vector<double> &normals)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GFace *gf = GModel::current()->getFaceByTag(tag);
   if(!gf) {
     Msg::Error("%s does not exist", _getEntityName(2, tag).c_str());
-    throw 2;
+    throw Msg::GetLastError();
   }
   normals.clear();
   if(parametricCoord.size() % 2) return;
@@ -793,12 +835,12 @@ gmsh::model::getParametrization(const int dim, const int tag,
                                 const std::vector<double> &coord,
                                 std::vector<double> &parametricCoord)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   parametricCoord.clear();
   GEntity *entity = GModel::current()->getEntityByTag(dim, tag);
   if(!entity) {
     Msg::Error("%s does not exist", _getEntityName(dim, tag).c_str());
-    throw 2;
+    throw Msg::GetLastError();
   }
   if(coord.size() % 3) return;
   if(dim == 1) {
@@ -825,13 +867,13 @@ GMSH_API void gmsh::model::getParametrizationBounds(const int dim,
                                                     std::vector<double> &min,
                                                     std::vector<double> &max)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   min.clear();
   max.clear();
   GEntity *entity = GModel::current()->getEntityByTag(dim, tag);
   if(!entity) {
     Msg::Error("%s does not exist", _getEntityName(dim, tag).c_str());
-    throw 2;
+    throw Msg::GetLastError();
   }
   for(int dim = 0; dim < entity->dim(); dim++) {
     Range<double> r = entity->parBounds(dim);
@@ -843,11 +885,11 @@ GMSH_API void gmsh::model::getParametrizationBounds(const int dim,
 GMSH_API int gmsh::model::isInside(const int dim, const int tag,
                                    const std::vector<double> &parametricCoord)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GEntity *entity = GModel::current()->getEntityByTag(dim, tag);
   if(!entity) {
     Msg::Error("%s does not exist", _getEntityName(dim, tag).c_str());
-    throw 2;
+    throw Msg::GetLastError();
   }
   int num = 0;
   if(dim == 1) {
@@ -872,17 +914,17 @@ GMSH_API void gmsh::model::reparametrizeOnSurface(
   const int surfaceTag, std::vector<double> &surfaceParametricCoord,
   const int which)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   surfaceParametricCoord.clear();
   GEntity *entity = GModel::current()->getEntityByTag(dim, tag);
   if(!entity) {
     Msg::Error("%s does not exist", _getEntityName(dim, tag).c_str());
-    throw 2;
+    throw Msg::GetLastError();
   }
   GFace *gf = GModel::current()->getFaceByTag(surfaceTag);
   if(!gf) {
     Msg::Error("%s does not exist", _getEntityName(2, surfaceTag).c_str());
-    throw 2;
+    throw Msg::GetLastError();
   }
   if(dim == 0) {
     GVertex *gv = static_cast<GVertex *>(entity);
@@ -905,13 +947,13 @@ GMSH_API void gmsh::model::getClosestPoint(const int dim, const int tag,
                                            std::vector<double> &closestCoord,
                                            std::vector<double> &parametricCoord)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   closestCoord.clear();
   parametricCoord.clear();
   GEntity *entity = GModel::current()->getEntityByTag(dim, tag);
   if(!entity) {
     Msg::Error("%s does not exist", _getEntityName(dim, tag).c_str());
-    throw 2;
+    throw Msg::GetLastError();
   }
   if(coord.size() % 3) return;
   if(dim == 1) {
@@ -944,7 +986,7 @@ GMSH_API void gmsh::model::getClosestPoint(const int dim, const int tag,
 GMSH_API void gmsh::model::setVisibility(const vectorpair &dimTags,
                                          const int value, const bool recursive)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   for(std::size_t i = 0; i < dimTags.size(); i++) {
     GEntity *ge = GModel::current()->getEntityByTag(
       dimTags[i].first, std::abs(dimTags[i].second));
@@ -955,11 +997,11 @@ GMSH_API void gmsh::model::setVisibility(const vectorpair &dimTags,
 GMSH_API void gmsh::model::getVisibility(const int dim, const int tag,
                                          int &value)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GEntity *ge = GModel::current()->getEntityByTag(dim, tag);
   if(!ge) {
     Msg::Error("%s does not exist", _getEntityName(dim, tag).c_str());
-    throw 2;
+    throw Msg::GetLastError();
   }
   value = ge->getVisibility();
 }
@@ -968,7 +1010,7 @@ GMSH_API void gmsh::model::setColor(const vectorpair &dimTags, const int r,
                                     const int g, const int b, const int a,
                                     const bool recursive)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   for(std::size_t i = 0; i < dimTags.size(); i++) {
     GEntity *ge = GModel::current()->getEntityByTag(
       dimTags[i].first, std::abs(dimTags[i].second));
@@ -982,11 +1024,11 @@ GMSH_API void gmsh::model::setColor(const vectorpair &dimTags, const int r,
 GMSH_API void gmsh::model::getColor(const int dim, const int tag, int &r,
                                     int &g, int &b, int &a)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GEntity *ge = GModel::current()->getEntityByTag(dim, tag);
   if(!ge) {
     Msg::Error("%s does not exist", _getEntityName(dim, tag).c_str());
-    throw 2;
+    throw Msg::GetLastError();
   }
   unsigned int value = ge->getColor();
   r = CTX::instance()->unpackRed(value);
@@ -998,11 +1040,11 @@ GMSH_API void gmsh::model::getColor(const int dim, const int tag, int &r,
 GMSH_API void gmsh::model::setCoordinates(const int tag, const double x,
                                           const double y, const double z)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GVertex *gv = GModel::current()->getVertexByTag(tag);
   if(!gv) {
     Msg::Error("%s does not exist", _getEntityName(0, tag).c_str());
-    throw 2;
+    throw Msg::GetLastError();
   }
   GPoint p(x, y, z);
   gv->setPosition(p);
@@ -1012,14 +1054,14 @@ GMSH_API void gmsh::model::setCoordinates(const int tag, const double x,
 
 GMSH_API void gmsh::model::mesh::generate(const int dim)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GModel::current()->mesh(dim);
   CTX::instance()->mesh.changed = ENT_ALL;
 }
 
 GMSH_API void gmsh::model::mesh::partition(const int numPart)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GModel::current()->partitionMesh(
     numPart >= 0 ? numPart : CTX::instance()->mesh.numPartitions);
   CTX::instance()->mesh.changed = ENT_ALL;
@@ -1027,14 +1069,14 @@ GMSH_API void gmsh::model::mesh::partition(const int numPart)
 
 GMSH_API void gmsh::model::mesh::unpartition()
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GModel::current()->unpartitionMesh();
   CTX::instance()->mesh.changed = ENT_ALL;
 }
 
 GMSH_API void gmsh::model::mesh::refine()
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GModel::current()->refineMesh(CTX::instance()->mesh.secondOrderLinear,
                                 CTX::instance()->mesh.algoSubdivide == 1,
                                 CTX::instance()->mesh.algoSubdivide == 2,
@@ -1044,7 +1086,7 @@ GMSH_API void gmsh::model::mesh::refine()
 
 GMSH_API void gmsh::model::mesh::recombine()
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GModel::current()->recombineMesh();
   CTX::instance()->mesh.changed = ENT_ALL;
 }
@@ -1053,7 +1095,7 @@ GMSH_API void gmsh::model::mesh::optimize(const std::string &how,
                                           const bool force, const int niter,
                                           const vectorpair &dimTags)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   if(dimTags.size()) {
     Msg::Warning(
       "Optimization of specified model entities is not interfaced yet");
@@ -1064,19 +1106,22 @@ GMSH_API void gmsh::model::mesh::optimize(const std::string &how,
 
 GMSH_API void gmsh::model::mesh::computeCrossField(std::vector<int> &tags)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_MESH)
-  if(computeCrossField(GModel::current(), tags)) throw 1;
+  if(computeCrossField(GModel::current(), tags)) {
+    Msg::Error("Could not compute cross field");
+    throw Msg::GetLastError();
+  }
 #else
   Msg::Error("computeCrossField requires the mesh module");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
 GMSH_API void gmsh::model::mesh::splitQuadrangles(const double quality,
                                                   const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_MESH)
   std::vector<GEntity *> entities;
   if(tag < 0) { GModel::current()->getEntities(entities, 2); }
@@ -1084,7 +1129,7 @@ GMSH_API void gmsh::model::mesh::splitQuadrangles(const double quality,
     GEntity *ge = GModel::current()->getEntityByTag(2, tag);
     if(!ge) {
       Msg::Error("%s does not exist", _getEntityName(2, tag).c_str());
-      throw 2;
+      throw Msg::GetLastError();
     }
     entities.push_back(ge);
   }
@@ -1095,13 +1140,13 @@ GMSH_API void gmsh::model::mesh::splitQuadrangles(const double quality,
   CTX::instance()->mesh.changed = ENT_ALL;
 #else
   Msg::Error("splitQuadrangles requires the mesh module");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
 GMSH_API void gmsh::model::mesh::setOrder(const int order)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GModel::current()->setOrderN(order, CTX::instance()->mesh.secondOrderLinear,
                                CTX::instance()->mesh.secondOrderIncomplete);
   CTX::instance()->mesh.changed = ENT_ALL;
@@ -1109,7 +1154,7 @@ GMSH_API void gmsh::model::mesh::setOrder(const int order)
 
 GMSH_API void gmsh::model::mesh::getLastEntityError(vectorpair &dimTags)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   std::vector<GEntity *> e = GModel::current()->getLastMeshEntityError();
   dimTags.clear();
   for(std::size_t i = 0; i < e.size(); i++)
@@ -1119,7 +1164,7 @@ GMSH_API void gmsh::model::mesh::getLastEntityError(vectorpair &dimTags)
 GMSH_API void
 gmsh::model::mesh::getLastNodeError(std::vector<std::size_t> &nodeTags)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   std::vector<MVertex *> v = GModel::current()->getLastMeshVertexError();
   nodeTags.clear();
   for(std::size_t i = 0; i < v.size(); i++) nodeTags.push_back(v[i]->getNum());
@@ -1127,7 +1172,7 @@ gmsh::model::mesh::getLastNodeError(std::vector<std::size_t> &nodeTags)
 
 GMSH_API void gmsh::model::mesh::clear(const vectorpair &dimTags)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   std::vector<GEntity *> entities;
   for(std::size_t i = 0; i < dimTags.size(); i++) {
     int dim = dimTags[i].first;
@@ -1135,7 +1180,7 @@ GMSH_API void gmsh::model::mesh::clear(const vectorpair &dimTags)
     GEntity *ge = GModel::current()->getEntityByTag(dim, tag);
     if(!ge) {
       Msg::Error("%s does not exist", _getEntityName(dim, tag).c_str());
-      throw 2;
+      throw Msg::GetLastError();
     }
     entities.push_back(ge);
   }
@@ -1216,7 +1261,7 @@ GMSH_API void gmsh::model::mesh::getNodes(std::vector<std::size_t> &nodeTags,
                                           const bool includeBoundary,
                                           const bool returnParametricCoord)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   nodeTags.clear();
   coord.clear();
   parametricCoord.clear();
@@ -1225,7 +1270,7 @@ GMSH_API void gmsh::model::mesh::getNodes(std::vector<std::size_t> &nodeTags,
     GEntity *ge = GModel::current()->getEntityByTag(dim, tag);
     if(!ge) {
       Msg::Error("%s does not exist", _getEntityName(dim, tag).c_str());
-      throw 2;
+      throw Msg::GetLastError();
     }
     entities.push_back(ge);
   }
@@ -1258,7 +1303,7 @@ GMSH_API void gmsh::model::mesh::getNodesByElementType(
   std::vector<double> &coord, std::vector<double> &parametricCoord,
   const int tag, const bool returnParametricCoord)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   nodeTags.clear();
   coord.clear();
   parametricCoord.clear();
@@ -1268,7 +1313,7 @@ GMSH_API void gmsh::model::mesh::getNodesByElementType(
     GEntity *ge = GModel::current()->getEntityByTag(dim, tag);
     if(!ge) {
       Msg::Error("%s does not exist", _getEntityName(dim, tag).c_str());
-      throw 2;
+      throw Msg::GetLastError();
     }
     entities.push_back(ge);
   }
@@ -1314,11 +1359,11 @@ GMSH_API void gmsh::model::mesh::getNode(const std::size_t nodeTag,
                                          std::vector<double> &coord,
                                          std::vector<double> &parametricCoord)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   MVertex *v = GModel::current()->getMeshVertexByTag(nodeTag);
   if(!v) {
     Msg::Error("Unknown node %d", nodeTag);
-    throw 2;
+    throw Msg::GetLastError();
   }
   coord.resize(3);
   coord[0] = v->x();
@@ -1335,15 +1380,15 @@ gmsh::model::mesh::setNode(const std::size_t nodeTag,
                            const std::vector<double> &coord,
                            const std::vector<double> &parametricCoord)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   MVertex *v = GModel::current()->getMeshVertexByTag(nodeTag);
   if(!v) {
     Msg::Error("Unknown node %d", nodeTag);
-    throw 2;
+    throw Msg::GetLastError();
   }
   if(coord.size() < 3) {
     Msg::Error("Less than three coordinates provided for node %d", nodeTag);
-    throw 2;
+    throw Msg::GetLastError();
   }
   v->setXYZ(coord[0], coord[1], coord[2]);
   if(parametricCoord.size() >= 1) v->setParameter(0, parametricCoord[0]);
@@ -1352,13 +1397,13 @@ gmsh::model::mesh::setNode(const std::size_t nodeTag,
 
 GMSH_API void gmsh::model::mesh::rebuildNodeCache(bool onlyIfNecessary)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GModel::current()->rebuildMeshVertexCache(onlyIfNecessary);
 }
 
 GMSH_API void gmsh::model::mesh::rebuildElementCache(bool onlyIfNecessary)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GModel::current()->rebuildMeshElementCache(onlyIfNecessary);
 }
 
@@ -1367,7 +1412,7 @@ gmsh::model::mesh::getNodesForPhysicalGroup(const int dim, const int tag,
                                             std::vector<std::size_t> &nodeTags,
                                             std::vector<double> &coord)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   nodeTags.clear();
   coord.clear();
   std::vector<MVertex *> v;
@@ -1387,11 +1432,11 @@ GMSH_API void gmsh::model::mesh::addNodes(
   const int dim, const int tag, const std::vector<std::size_t> &nodeTags,
   const std::vector<double> &coord, const std::vector<double> &parametricCoord)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GEntity *ge = GModel::current()->getEntityByTag(dim, tag);
   if(!ge) {
     Msg::Error("%s does not exist", _getEntityName(dim, tag).c_str());
-    throw 2;
+    throw Msg::GetLastError();
   }
   int numNodeTags = nodeTags.size(), numNodes = nodeTags.size();
   if(!numNodeTags) { // this is allowed: we will assign new tags
@@ -1399,13 +1444,13 @@ GMSH_API void gmsh::model::mesh::addNodes(
   }
   if((int)coord.size() != 3 * numNodes) {
     Msg::Error("Wrong number of coordinates");
-    throw 2;
+    throw Msg::GetLastError();
   }
   bool param = false;
   if(parametricCoord.size()) {
     if((int)parametricCoord.size() != dim * numNodes) {
       Msg::Error("Wrong number of parametric coordinates");
-      throw 2;
+      throw Msg::GetLastError();
     }
     param = true;
   }
@@ -1433,19 +1478,19 @@ GMSH_API void gmsh::model::mesh::addNodes(
 
 GMSH_API void gmsh::model::mesh::reclassifyNodes()
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GModel::current()->pruneMeshVertexAssociations();
 }
 
 GMSH_API void gmsh::model::mesh::relocateNodes(const int dim, const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   std::vector<GEntity *> entities;
   if(dim >= 0 && tag >= 0) {
     GEntity *ge = GModel::current()->getEntityByTag(dim, tag);
     if(!ge) {
       Msg::Error("%s does not exist", _getEntityName(dim, tag).c_str());
-      throw 2;
+      throw Msg::GetLastError();
     }
     entities.push_back(ge);
   }
@@ -1465,7 +1510,7 @@ _getEntitiesForElementTypes(int dim, int tag,
     GEntity *ge = GModel::current()->getEntityByTag(dim, tag);
     if(!ge) {
       Msg::Error("%s does not exist", _getEntityName(dim, tag).c_str());
-      throw 2;
+      throw Msg::GetLastError();
     }
     entities.push_back(ge);
   }
@@ -1517,7 +1562,7 @@ GMSH_API void gmsh::model::mesh::getElements(
   std::vector<std::vector<std::size_t> > &nodeTags, const int dim,
   const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   elementTypes.clear();
   elementTags.clear();
   nodeTags.clear();
@@ -1549,11 +1594,11 @@ GMSH_API void gmsh::model::mesh::getElement(const std::size_t elementTag,
                                             int &elementType,
                                             std::vector<std::size_t> &nodeTags)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   MElement *e = GModel::current()->getMeshElementByTag(elementTag);
   if(!e) {
     Msg::Error("Unknown element %d", elementTag);
-    throw 2;
+    throw Msg::GetLastError();
   }
   elementType = e->getTypeForMSH();
   nodeTags.clear();
@@ -1561,7 +1606,7 @@ GMSH_API void gmsh::model::mesh::getElement(const std::size_t elementTag,
     MVertex *v = e->getVertex(i);
     if(!v) {
       Msg::Error("Unknown node in element %d", elementTag);
-      throw 2;
+      throw Msg::GetLastError();
     }
     nodeTags.push_back(v->getNum());
   }
@@ -1572,12 +1617,12 @@ GMSH_API void gmsh::model::mesh::getElementByCoordinates(
   int &elementType, std::vector<std::size_t> &nodeTags, double &u, double &v,
   double &w, const int dim, const bool strict)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   SPoint3 xyz(x, y, z), uvw;
   MElement *e = GModel::current()->getMeshElementByCoord(xyz, uvw, dim, strict);
   if(!e) {
     Msg::Error("No element found at (%g, %g, %g)", x, y, z);
-    throw 2;
+    throw Msg::GetLastError();
   }
   elementTag = e->getNum();
   elementType = e->getTypeForMSH();
@@ -1586,7 +1631,7 @@ GMSH_API void gmsh::model::mesh::getElementByCoordinates(
     MVertex *v = e->getVertex(i);
     if(!v) {
       Msg::Error("Unknown node in element %d", elementTag);
-      throw 2;
+      throw Msg::GetLastError();
     }
     nodeTags.push_back(v->getNum());
   }
@@ -1599,14 +1644,14 @@ GMSH_API void gmsh::model::mesh::getElementsByCoordinates(
   const double x, const double y, const double z,
   std::vector<std::size_t> &elementTags, const int dim, const bool strict)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   SPoint3 xyz(x, y, z), uvw;
   elementTags.clear();
   std::vector<MElement *> e =
     GModel::current()->getMeshElementsByCoord(xyz, dim, strict);
   if(e.empty()) {
     Msg::Error("No element found at (%g, %g, %g)", x, y, z);
-    throw 2;
+    throw Msg::GetLastError();
   }
   for(std::size_t i = 0; i < e.size(); i++) {
     elementTags.push_back(e[i]->getNum());
@@ -1617,11 +1662,11 @@ GMSH_API void gmsh::model::mesh::getLocalCoordinatesInElement(
   const std::size_t elementTag, const double x, const double y, const double z,
   double &u, double &v, double &w)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   MElement *e = GModel::current()->getMeshElementByTag(elementTag);
   if(!e) {
     Msg::Error("Unknown element %d", elementTag);
-    throw 2;
+    throw Msg::GetLastError();
   }
   double xyz[3] = {x, y, z}, uvw[3];
   e->xyz2uvw(xyz, uvw);
@@ -1650,7 +1695,7 @@ static void _addElements(int dim, int tag, GEntity *ge, int type,
   if(!numEle) return;
   if(numEle * numNodesPerEle != nodeTags.size()) {
     Msg::Error("Wrong number of node tags for element type %d", type);
-    throw 2;
+    throw Msg::GetLastError();
   }
   std::vector<MElement *> elements(numEle);
   std::vector<MVertex *> nodes(numNodesPerEle);
@@ -1663,7 +1708,7 @@ static void _addElements(int dim, int tag, GEntity *ge, int type,
       nodes[k] = GModel::current()->getMeshVertexByTag(vtag);
       if(!nodes[k]) {
         Msg::Error("Unknown node %d", vtag);
-        throw 2;
+        throw Msg::GetLastError();
       }
     }
     elements[j] = f.create(type, nodes, etag);
@@ -1706,7 +1751,7 @@ static void _addElements(int dim, int tag, GEntity *ge, int type,
   if(!ok) {
     Msg::Error("Wrong type of element for %s",
                _getEntityName(dim, tag).c_str());
-    throw 2;
+    throw Msg::GetLastError();
   }
 }
 
@@ -1715,19 +1760,19 @@ GMSH_API void gmsh::model::mesh::addElements(
   const std::vector<std::vector<std::size_t> > &elementTags,
   const std::vector<std::vector<std::size_t> > &nodeTags)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GEntity *ge = GModel::current()->getEntityByTag(dim, tag);
   if(!ge) {
     Msg::Error("%s does not exist", _getEntityName(dim, tag).c_str());
-    throw 2;
+    throw Msg::GetLastError();
   }
   if(elementTypes.size() != elementTags.size()) {
     Msg::Error("Wrong number of element tags");
-    throw 2;
+    throw Msg::GetLastError();
   }
   if(elementTypes.size() != nodeTags.size()) {
     Msg::Error("Wrong number of node tags");
-    throw 2;
+    throw Msg::GetLastError();
   }
 
   for(std::size_t i = 0; i < elementTypes.size(); i++)
@@ -1740,12 +1785,12 @@ GMSH_API void gmsh::model::mesh::addElementsByType(
   const std::vector<std::size_t> &elementTags,
   const std::vector<std::size_t> &nodeTags)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   int dim = ElementType::getDimension(elementType);
   GEntity *ge = GModel::current()->getEntityByTag(dim, tag);
   if(!ge) {
     Msg::Error("%s does not exist", _getEntityName(dim, tag).c_str());
-    throw 2;
+    throw Msg::GetLastError();
   }
   _addElements(dim, tag, ge, elementType, elementTags, nodeTags);
   GModel::current()->destroyMeshCaches();
@@ -1754,7 +1799,7 @@ GMSH_API void gmsh::model::mesh::addElementsByType(
 GMSH_API void gmsh::model::mesh::getElementTypes(std::vector<int> &elementTypes,
                                                  const int dim, const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   elementTypes.clear();
   std::map<int, std::vector<GEntity *> > typeEnt;
   _getEntitiesForElementTypes(dim, tag, typeEnt);
@@ -1769,7 +1814,7 @@ GMSH_API int gmsh::model::mesh::getElementType(const std::string &family,
                                                const int order,
                                                const bool serendip)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   int familyType = (family == "point") ?
                      TYPE_PNT :
                      (family == "line") ?
@@ -1798,7 +1843,7 @@ GMSH_API void gmsh::model::mesh::getElementProperties(
   const int elementType, std::string &name, int &dim, int &order, int &numNodes,
   std::vector<double> &localNodeCoord, int &numPrimaryNodes)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   const char *n;
   MElement::getInfoMSH(elementType, &n);
   name = n;
@@ -1813,7 +1858,7 @@ GMSH_API void gmsh::model::mesh::getElementProperties(
   numNodes = basis->points.size1();
   if(numNodes != ElementType::getNumVertices(elementType)) {
     Msg::Error("Size of basis incompatible with element type");
-    throw 2;
+    throw Msg::GetLastError();
   }
   for(int i = 0; i < basis->points.size1(); i++)
     for(int j = 0; j < basis->points.size2(); j++)
@@ -1828,7 +1873,7 @@ GMSH_API void gmsh::model::mesh::getElementsByType(
   std::vector<std::size_t> &nodeTags, const int tag, const std::size_t task,
   const std::size_t numTasks)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   int dim = ElementType::getDimension(elementType);
   std::map<int, std::vector<GEntity *> > typeEnt;
   _getEntitiesForElementTypes(dim, tag, typeEnt);
@@ -1840,7 +1885,7 @@ GMSH_API void gmsh::model::mesh::getElementsByType(
   const int numNodes = ElementType::getNumVertices(elementType);
   if(!numTasks) {
     Msg::Error("Number of tasks should be > 0");
-    throw 4;
+    throw Msg::GetLastError();
   }
   const std::size_t begin = (task * numElements) / numTasks;
   const std::size_t end = ((task + 1) * numElements) / numTasks;
@@ -1858,12 +1903,12 @@ GMSH_API void gmsh::model::mesh::getElementsByType(
   if(haveElementTags && (elementTags.size() < numElements)) {
     Msg::Error("Wrong size of elementTags array (%d < %d)", elementTags.size(),
                numElements);
-    throw 4;
+    throw Msg::GetLastError();
   }
   if(haveNodeTags && (nodeTags.size() < numElements * numNodes)) {
     Msg::Error("Wrong size of nodeTags array (%d < %d)", nodeTags.size(),
                numElements * numNodes);
-    throw 4;
+    throw Msg::GetLastError();
   }
   size_t o = 0;
   size_t idx = begin * numNodes;
@@ -1889,7 +1934,7 @@ GMSH_API void gmsh::model::mesh::preallocateElementsByType(
   std::vector<std::size_t> &elementTags, std::vector<std::size_t> &nodeTags,
   const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   int dim = ElementType::getDimension(elementType);
   std::map<int, std::vector<GEntity *> > typeEnt;
   _getEntitiesForElementTypes(dim, tag, typeEnt);
@@ -1965,7 +2010,7 @@ GMSH_API void gmsh::model::mesh::getJacobians(
   std::vector<double> &coord, const int tag, const std::size_t task,
   const std::size_t numTasks)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   int dim = ElementType::getDimension(elementType);
   std::map<int, std::vector<GEntity *> > typeEnt;
   _getEntitiesForElementTypes(dim, tag, typeEnt);
@@ -1999,24 +2044,24 @@ GMSH_API void gmsh::model::mesh::getJacobians(
     }
     if(!numTasks) {
       Msg::Error("Number of tasks should be > 0");
-      throw 4;
+      throw Msg::GetLastError();
     }
     const size_t begin = (task * numElements) / numTasks;
     const size_t end = ((task + 1) * numElements) / numTasks;
     if(haveDeterminants && (end * numPoints > determinants.size())) {
       Msg::Error("Wrong size of determinants array (%d < %d)",
                  determinants.size(), end * numPoints);
-      throw 4;
+      throw Msg::GetLastError();
     }
     if(haveJacobians && (9 * end * numPoints > jacobians.size())) {
       Msg::Error("Wrong size of jacobians array (%d < %d)", jacobians.size(),
                  9 * end * numPoints);
-      throw 4;
+      throw Msg::GetLastError();
     }
     if(havePoints && (3 * end * numPoints > coord.size())) {
       Msg::Error("Wrong size of points array (%d < %d)", coord.size(),
                  3 * end * numPoints);
-      throw 4;
+      throw Msg::GetLastError();
     }
     if(haveDeterminants && haveJacobians && havePoints) {
       std::vector<std::vector<SVector3> > gsf;
@@ -2196,11 +2241,11 @@ GMSH_API void gmsh::model::mesh::getJacobians(
     }
     else {
       Msg::Error("The case with 'haveDeterminants = %s', `haveJacobians = %s` "
-                 "and 'havePoints = %s' is not yet implemented.",
+                 "and 'havePoints = %s' is not yet implemented",
                  (haveDeterminants ? "true" : "false"),
                  (haveJacobians ? "true" : "false"),
                  (havePoints ? "true" : "false"));
-      throw 2;
+      throw Msg::GetLastError();
     }
     // Add other combinaisons if necessary
   }
@@ -2212,7 +2257,7 @@ GMSH_API void gmsh::model::mesh::preallocateJacobians(
   std::vector<double> &jacobians, std::vector<double> &determinants,
   std::vector<double> &coord, const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   int dim = ElementType::getDimension(elementType);
   BasisFactory::getNodalBasis(elementType);
   std::map<int, std::vector<GEntity *> > typeEnt;
@@ -2242,11 +2287,11 @@ GMSH_API void gmsh::model::mesh::getJacobian(
   std::vector<double> &jacobians, std::vector<double> &determinants,
   std::vector<double> &coord)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   MElement *e = GModel::current()->getMeshElementByTag(elementTag);
   if(!e) {
     Msg::Error("Unknown element %d", elementTag);
-    throw 2;
+    throw Msg::GetLastError();
   }
   int numPoints = localCoord.size() / 3;
   if(!numPoints) {
@@ -2282,7 +2327,7 @@ GMSH_API void gmsh::model::mesh::getBasisFunctions(
   std::vector<double> &basisFunctions, int &numOrientations,
   const std::vector<int> &wantedOrientations)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   numComponents = 0;
   basisFunctions.clear();
   std::string fsName = "";
@@ -2290,7 +2335,7 @@ GMSH_API void gmsh::model::mesh::getBasisFunctions(
   if(!_getFunctionSpaceInfo(functionSpaceType, fsName, fsOrder,
                             numComponents)) {
     Msg::Error("Unknown function space type '%s'", functionSpaceType.c_str());
-    throw 2;
+    throw Msg::GetLastError();
   }
 
   const std::size_t numberOfGaussPoints = localCoord.size() / 3;
@@ -2300,16 +2345,16 @@ GMSH_API void gmsh::model::mesh::getBasisFunctions(
     // Check if there is no error in wantedOrientations
     if(wantedOrientations.size() != 0) {
       if(wantedOrientations.size() > 1) {
-        Msg::Error("Asking for more orientation that there exist.");
-        throw 10;
+        Msg::Error("Asking for more orientation that there exist");
+        throw Msg::GetLastError();
       }
 
       if(wantedOrientations[0] != 0) {
         Msg::Error(
-          "Orientation %i does not exist for function stace named '%s' on %s.",
+          "Orientation %i does not exist for function stace named '%s' on %s",
           wantedOrientations[0], fsName.c_str(),
           ElementType::nameOfParentType(familyType, true).c_str());
-        throw 11;
+        throw Msg::GetLastError();
       }
     }
 
@@ -2375,9 +2420,9 @@ GMSH_API void gmsh::model::mesh::getBasisFunctions(
         basis = new HierarchicalBasisH1Point();
       } break;
       default:
-        Msg::Error("Unknown familyType %i for basis function type %s.",
+        Msg::Error("Unknown familyType %i for basis function type %s",
                    familyType, fsName.c_str());
-        throw 2;
+        throw Msg::GetLastError();
       }
     }
     else if(fsName == "HcurlLegendre" || fsName == "CurlHcurlLegendre") {
@@ -2401,14 +2446,14 @@ GMSH_API void gmsh::model::mesh::getBasisFunctions(
         basis = new HierarchicalBasisHcurlLine(fsOrder);
       } break;
       default:
-        Msg::Error("Unknown familyType %i for basis function type %s.",
+        Msg::Error("Unknown familyType %i for basis function type %s",
                    familyType, fsName.c_str());
-        throw 2;
+        throw Msg::GetLastError();
       }
     }
     else {
       Msg::Error("Unknown function space named '%s'", fsName.c_str());
-      throw 3;
+      throw Msg::GetLastError();
     }
 
     const std::size_t vSize = basis->getnVertexFunction();
@@ -2430,17 +2475,17 @@ GMSH_API void gmsh::model::mesh::getBasisFunctions(
     // Check if there is no error in wantedOrientations
     if(wantedOrientations.size() != 0) {
       if(wantedOrientations.size() > maxOrientation) {
-        Msg::Error("Asking for more orientation that there exist.");
-        throw 10;
+        Msg::Error("Asking for more orientation that there exist");
+        throw Msg::GetLastError();
       }
       for(unsigned int i = 0; i < wantedOrientations.size(); ++i) {
         if(wantedOrientations[i] >= static_cast<int>(maxOrientation) ||
            wantedOrientations[i] < 0) {
           Msg::Error("Orientation %i does not exist for function stace named "
-                     "'%s' on %s.",
+                     "'%s' on %s",
                      wantedOrientations[i], fsName.c_str(),
                      ElementType::nameOfParentType(familyType, true).c_str());
-          throw 11;
+          throw Msg::GetLastError();
         }
       }
       std::vector<int> sortedWantedOrientations = wantedOrientations;
@@ -2449,8 +2494,8 @@ GMSH_API void gmsh::model::mesh::getBasisFunctions(
       int previousInt = sortedWantedOrientations[0];
       for(unsigned int i = 1; i < sortedWantedOrientations.size(); ++i) {
         if(previousInt == sortedWantedOrientations[i]) {
-          Msg::Error("Duplicate wanted orientation found.");
-          throw 12;
+          Msg::Error("Duplicate wanted orientation found");
+          throw Msg::GetLastError();
         }
         previousInt = sortedWantedOrientations[i];
       }
@@ -2484,9 +2529,9 @@ GMSH_API void gmsh::model::mesh::getBasisFunctions(
       element = new MPoint(vertices);
     } break;
     default:
-      Msg::Error("Unknown familyType %i for basis function type %s.",
+      Msg::Error("Unknown familyType %i for basis function type %s",
                  familyType, fsName.c_str());
-      throw 2;
+      throw Msg::GetLastError();
     }
 
     switch(numComponents) {
@@ -2827,7 +2872,7 @@ GMSH_API void gmsh::model::mesh::getBasisFunctionsOrientationForElements(
   std::vector<int> &basisFunctionsOrientation, const int tag,
   const std::size_t task, const std::size_t numTasks)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 
   if(!basisFunctionsOrientation.size()) {
     if(numTasks > 1) {
@@ -2846,7 +2891,7 @@ GMSH_API void gmsh::model::mesh::getBasisFunctionsOrientationForElements(
   if(!_getFunctionSpaceInfo(functionSpaceType, fsName, basisOrder,
                             numComponents)) {
     Msg::Error("Unknown function space type '%s'", functionSpaceType.c_str());
-    throw 2;
+    throw Msg::GetLastError();
   }
 
   const int dim = ElementType::getDimension(elementType);
@@ -2863,7 +2908,7 @@ GMSH_API void gmsh::model::mesh::getBasisFunctionsOrientationForElements(
   if(numElements != basisFunctionsOrientation.size()) {
     Msg::Error("Wrong size of 'basisFunctionsOrientation' vector (%i != %i)",
                numElements, basisFunctionsOrientation.size());
-    throw 3;
+    throw Msg::GetLastError();
   }
 
   if(fsName == "Lagrange" || fsName == "GradLagrange") { // Lagrange type
@@ -2934,7 +2979,7 @@ GMSH_API void gmsh::model::mesh::getBasisFunctionsOrientationForElement(
   const std::size_t elementTag, const std::string &functionSpaceType,
   int &basisFunctionsOrientation)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 
   MElement *e = GModel::current()->getMeshElementByTag(elementTag);
   int elementType = e->getTypeForMSH();
@@ -2946,7 +2991,7 @@ GMSH_API void gmsh::model::mesh::getBasisFunctionsOrientationForElement(
   if(!_getFunctionSpaceInfo(functionSpaceType, fsName, basisOrder,
                             numComponents)) {
     Msg::Error("Unknown function space type '%s'", functionSpaceType.c_str());
-    throw 2;
+    throw Msg::GetLastError();
   }
 
   if(fsName == "Lagrange" || fsName == "GradLagrange") { // Lagrange type
@@ -2995,7 +3040,7 @@ GMSH_API int
 gmsh::model::mesh::getNumberOfOrientations(const int elementType,
                                            const std::string &functionSpaceType)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 
   int basisOrder = 0;
   std::string fsName = "";
@@ -3003,7 +3048,7 @@ gmsh::model::mesh::getNumberOfOrientations(const int elementType,
   if(!_getFunctionSpaceInfo(functionSpaceType, fsName, basisOrder,
                             numComponents)) {
     Msg::Error("Unknown function space type '%s'", functionSpaceType.c_str());
-    throw 2;
+    throw Msg::GetLastError();
   }
 
   if(fsName == "Lagrange" || fsName == "GradLagrange") { // Lagrange type
@@ -3025,7 +3070,7 @@ gmsh::model::mesh::preallocateBasisFunctionsOrientationForElements(
   const int elementType, std::vector<int> &basisFunctionsOrientation,
   const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 
   const int dim = ElementType::getDimension(elementType);
   std::map<int, std::vector<GEntity *> > typeEnt;
@@ -3090,9 +3135,9 @@ GMSH_API void gmsh::model::mesh::getLocalMultipliersForHcurl0(
     basis = new HierarchicalBasisHcurlLine(basisOrder);
   } break;
   default:
-    Msg::Error("Unknown familyType %i for basis function type %s.", familyType,
+    Msg::Error("Unknown familyType %i for basis function type %s", familyType,
                fsName.c_str());
-    throw 2;
+    throw Msg::GetLastError();
   }
   // compute the number of Element :
   std::size_t numElements = 0;
@@ -3127,7 +3172,7 @@ GMSH_API void gmsh::model::mesh::getKeysForElements(
   gmsh::vectorpair &keys, std::vector<double> &coord, const int tag,
   const bool generateCoord)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   coord.clear();
   keys.clear();
   int order = 0;
@@ -3135,7 +3180,7 @@ GMSH_API void gmsh::model::mesh::getKeysForElements(
   std::string fsName = "";
   if(!_getFunctionSpaceInfo(functionSpaceType, fsName, order, numComponents)) {
     Msg::Error("Unknown function space type '%s'", functionSpaceType.c_str());
-    throw 2;
+    throw Msg::GetLastError();
   }
   int dim = ElementType::getDimension(elementType);
   std::map<int, std::vector<GEntity *> > typeEnt;
@@ -3168,9 +3213,9 @@ GMSH_API void gmsh::model::mesh::getKeysForElements(
       basis = new HierarchicalBasisH1Point();
     } break;
     default:
-      Msg::Error("Unknown familyType %i for basis function type %s.",
+      Msg::Error("Unknown familyType %i for basis function type %s",
                  familyType, fsName.c_str());
-      throw 2;
+      throw Msg::GetLastError();
     }
   }
   else if(fsName == "HcurlLegendre" || fsName == "CurlHcurlLegendre") {
@@ -3194,9 +3239,9 @@ GMSH_API void gmsh::model::mesh::getKeysForElements(
       basis = new HierarchicalBasisHcurlLine(order);
     } break;
     default:
-      Msg::Error("Unknown familyType %i for basis function type %s.",
+      Msg::Error("Unknown familyType %i for basis function type %s",
                  familyType, fsName.c_str());
-      throw 2;
+      throw Msg::GetLastError();
     }
   }
   else if(fsName == "IsoParametric" || fsName == "Lagrange" ||
@@ -3239,7 +3284,7 @@ GMSH_API void gmsh::model::mesh::getKeysForElements(
   }
   else {
     Msg::Error("Unknown function space named '%s'", fsName.c_str());
-    throw 3;
+    throw Msg::GetLastError();
   }
 
   int vSize = basis->getnVertexFunction();
@@ -3379,7 +3424,7 @@ GMSH_API void gmsh::model::mesh::getKeysForElement(
   const std::size_t elementTag, const std::string &functionSpaceType,
   gmsh::vectorpair &keys, std::vector<double> &coord, const bool generateCoord)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   coord.clear();
   keys.clear();
   int order = 0;
@@ -3387,7 +3432,7 @@ GMSH_API void gmsh::model::mesh::getKeysForElement(
   std::string fsName = "";
   if(!_getFunctionSpaceInfo(functionSpaceType, fsName, order, numComponents)) {
     Msg::Error("Unknown function space type '%s'", functionSpaceType.c_str());
-    throw 2;
+    throw Msg::GetLastError();
   }
   MElement *e = GModel::current()->getMeshElementByTag(elementTag);
   int elementType = e->getTypeForMSH();
@@ -3418,9 +3463,9 @@ GMSH_API void gmsh::model::mesh::getKeysForElement(
       basis = new HierarchicalBasisH1Point();
     } break;
     default:
-      Msg::Error("Unknown familyType %i for basis function type %s.",
+      Msg::Error("Unknown familyType %i for basis function type %s",
                  familyType, fsName.c_str());
-      throw 2;
+      throw Msg::GetLastError();
     }
   }
   else if(fsName == "HcurlLegendre" || fsName == "CurlHcurlLegendre") {
@@ -3444,9 +3489,9 @@ GMSH_API void gmsh::model::mesh::getKeysForElement(
       basis = new HierarchicalBasisHcurlLine(order);
     } break;
     default:
-      Msg::Error("Unknown familyType %i for basis function type %s.",
+      Msg::Error("Unknown familyType %i for basis function type %s",
                  familyType, fsName.c_str());
-      throw 2;
+      throw Msg::GetLastError();
     }
   }
   else if(fsName == "IsoParametric" || fsName == "Lagrange" ||
@@ -3465,7 +3510,7 @@ GMSH_API void gmsh::model::mesh::getKeysForElement(
   }
   else {
     Msg::Error("Unknown function space named '%s'", fsName.c_str());
-    throw 3;
+    throw Msg::GetLastError();
   }
 
   int vSize = basis->getnVertexFunction();
@@ -3599,7 +3644,7 @@ GMSH_API int gmsh::model::mesh::getNumberOfKeysForElements(
   if(!_getFunctionSpaceInfo(functionSpaceType, fsName, basisOrder,
                             numComponents)) {
     Msg::Error("Unknown function space type '%s'", functionSpaceType.c_str());
-    throw 2;
+    throw Msg::GetLastError();
   }
   int familyType = ElementType::getParentType(elementType);
   if(fsName == "H1Legendre" || fsName == "GradH1Legendre") {
@@ -3627,9 +3672,9 @@ GMSH_API int gmsh::model::mesh::getNumberOfKeysForElements(
       basis = new HierarchicalBasisH1Point();
     } break;
     default:
-      Msg::Error("Unknown familyType %i for basis function type %s.",
+      Msg::Error("Unknown familyType %i for basis function type %s",
                  familyType, fsName.c_str());
-      throw 2;
+      throw Msg::GetLastError();
     }
     int vSize = basis->getnVertexFunction();
     int bSize = basis->getnBubbleFunction();
@@ -3661,9 +3706,9 @@ GMSH_API int gmsh::model::mesh::getNumberOfKeysForElements(
       basis = new HierarchicalBasisHcurlLine(basisOrder);
     } break;
     default:
-      Msg::Error("Unknown familyType %i for basis function type %s.",
+      Msg::Error("Unknown familyType %i for basis function type %s",
                  familyType, fsName.c_str());
-      throw 2;
+      throw Msg::GetLastError();
     }
     int vSize = basis->getnVertexFunction();
     int bSize = basis->getnBubbleFunction();
@@ -3688,7 +3733,7 @@ GMSH_API int gmsh::model::mesh::getNumberOfKeysForElements(
   }
   else {
     Msg::Error("Unknown function space named '%s'", fsName.c_str());
-    throw 3;
+    throw Msg::GetLastError();
   }
 
   return numberOfKeys;
@@ -3705,7 +3750,7 @@ GMSH_API void gmsh::model::mesh::getInformationForElements(
   if(!_getFunctionSpaceInfo(functionSpaceType, fsName, basisOrder,
                             numComponents)) {
     Msg::Error("Unknown function space type '%s'", functionSpaceType.c_str());
-    throw 2;
+    throw Msg::GetLastError();
   }
   HierarchicalBasis *basis(0);
   int familyType = ElementType::getParentType(elementType);
@@ -3733,9 +3778,9 @@ GMSH_API void gmsh::model::mesh::getInformationForElements(
       basis = new HierarchicalBasisH1Point();
     } break;
     default:
-      Msg::Error("Unknown familyType %i for basis function type %s.",
+      Msg::Error("Unknown familyType %i for basis function type %s",
                  familyType, fsName.c_str());
-      throw 3;
+      throw Msg::GetLastError();
     }
   }
   else if(fsName == "HcurlLegendre" || fsName == "CurlHcurlLegendre") {
@@ -3759,9 +3804,9 @@ GMSH_API void gmsh::model::mesh::getInformationForElements(
       basis = new HierarchicalBasisHcurlLine(basisOrder);
     } break;
     default:
-      Msg::Error("Unknown familyType %i for basis function type %s.",
+      Msg::Error("Unknown familyType %i for basis function type %s",
                  familyType, fsName.c_str());
-      throw 3;
+      throw Msg::GetLastError();
     }
   }
   else if(fsName == "IsoParametric" || fsName == "Lagrange" ||
@@ -3779,7 +3824,10 @@ GMSH_API void gmsh::model::mesh::getInformationForElements(
     std::size_t numberOfBubble = basis->getNumBubbleShapeFunctions();
     int dim = ElementType::getDimension(elementType);
 
-    if(numberOfBubble > numberOfKeys) { throw 4; }
+    if(numberOfBubble > numberOfKeys) {
+      Msg::Error("Number of bubble functions greater than number of keys");
+      throw Msg::GetLastError();
+    }
 
     infoKeys.reserve(keys.size());
     for(size_t i = 0; i < keys.size() / numberOfKeys; ++i) {
@@ -3794,7 +3842,7 @@ GMSH_API void gmsh::model::mesh::getInformationForElements(
   }
   else {
     Msg::Error("Unknown function space named '%s'", fsName.c_str());
-    throw 5;
+    throw Msg::GetLastError();
   }
 
   int vSize = basis->getnVertexFunction();
@@ -3824,7 +3872,7 @@ GMSH_API void gmsh::model::mesh::getBarycenters(
   std::vector<double> &barycenters, const std::size_t task,
   const std::size_t numTasks)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   int dim = ElementType::getDimension(elementType);
   std::map<int, std::vector<GEntity *> > typeEnt;
   _getEntitiesForElementTypes(dim, tag, typeEnt);
@@ -3837,7 +3885,7 @@ GMSH_API void gmsh::model::mesh::getBarycenters(
   }
   if(!numTasks) {
     Msg::Error("Number of tasks should be > 0");
-    throw 4;
+    throw Msg::GetLastError();
   }
   const size_t begin = (task * numElements) / numTasks;
   const size_t end = ((task + 1) * numElements) / numTasks;
@@ -3897,14 +3945,14 @@ GMSH_API void gmsh::model::mesh::getIntegrationPoints(
   const int elementType, const std::string &integrationType,
   std::vector<double> &localCoord, std::vector<double> &weigths)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   localCoord.clear();
   weigths.clear();
   std::string intName = "";
   int intOrder = 0;
   if(!_getIntegrationInfo(integrationType, intName, intOrder)) {
     Msg::Error("Unknown quadrature type '%s'", integrationType.c_str());
-    throw 2;
+    throw Msg::GetLastError();
   }
   // get quadrature info
   int familyType = ElementType::getParentType(elementType);
@@ -3913,7 +3961,7 @@ GMSH_API void gmsh::model::mesh::getIntegrationPoints(
   gaussIntegration::get(familyType, intOrder, pts, weights);
   if(pts.size1() != weights.size() || pts.size2() != 3) {
     Msg::Error("Wrong integration point format");
-    throw 3;
+    throw Msg::GetLastError();
   }
   localCoord.resize(3 * pts.size1());
   weigths.resize(pts.size1());
@@ -3928,7 +3976,7 @@ GMSH_API void gmsh::model::mesh::getIntegrationPoints(
 GMSH_API void gmsh::model::mesh::preallocateBarycenters(
   const int elementType, std::vector<double> &barycenters, const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   int dim = ElementType::getDimension(elementType);
   std::map<int, std::vector<GEntity *> > typeEnt;
   _getEntitiesForElementTypes(dim, tag, typeEnt);
@@ -3945,7 +3993,7 @@ GMSH_API void gmsh::model::mesh::getElementEdgeNodes(
   const int elementType, std::vector<std::size_t> &nodeTags, const int tag,
   const bool primary, const std::size_t task, const std::size_t numTasks)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   int dim = ElementType::getDimension(elementType);
   std::map<int, std::vector<GEntity *> > typeEnt;
   _getEntitiesForElementTypes(dim, tag, typeEnt);
@@ -3972,7 +4020,7 @@ GMSH_API void gmsh::model::mesh::getElementEdgeNodes(
   }
   if(!numTasks) {
     Msg::Error("Number of tasks should be > 0");
-    throw 4;
+    throw Msg::GetLastError();
   }
   const size_t begin = (task * numElements) / numTasks;
   const size_t end = ((task + 1) * numElements) / numTasks;
@@ -4009,7 +4057,7 @@ GMSH_API void gmsh::model::mesh::getElementFaceNodes(
   const int tag, const bool primary, const std::size_t task,
   const std::size_t numTasks)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   int dim = ElementType::getDimension(elementType);
   std::map<int, std::vector<GEntity *> > typeEnt;
   _getEntitiesForElementTypes(dim, tag, typeEnt);
@@ -4041,7 +4089,7 @@ GMSH_API void gmsh::model::mesh::getElementFaceNodes(
   }
   if(!numTasks) {
     Msg::Error("Number of tasks should be > 0");
-    throw 4;
+    throw Msg::GetLastError();
   }
   const size_t begin = (task * numElements) / numTasks;
   const size_t end = ((task + 1) * numElements) / numTasks;
@@ -4081,13 +4129,13 @@ gmsh::model::mesh::getGhostElements(const int dim, const int tag,
                                     std::vector<std::size_t> &elementTags,
                                     std::vector<int> &partitions)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   elementTags.clear();
   partitions.clear();
   GEntity *ge = GModel::current()->getEntityByTag(dim, tag);
   if(!ge) {
     Msg::Error("%s does not exist", _getEntityName(dim, tag).c_str());
-    throw 2;
+    throw Msg::GetLastError();
   }
   std::map<MElement *, int> ghostCells;
   if(ge->geomType() == GEntity::GhostCurve)
@@ -4107,7 +4155,7 @@ gmsh::model::mesh::getGhostElements(const int dim, const int tag,
 GMSH_API void gmsh::model::mesh::setSize(const vectorpair &dimTags,
                                          const double size)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   for(std::size_t i = 0; i < dimTags.size(); i++) {
     int dim = dimTags[i].first, tag = dimTags[i].second;
     if(dim == 0) {
@@ -4121,7 +4169,7 @@ GMSH_API void gmsh::model::mesh::setSizeAtParametricPoints(
   const int dim, const int tag, const std::vector<double> &parametricCoord,
   const std::vector<double> &sizes)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   if(dim == 1) {
     GEdge *ge = GModel::current()->getEdgeByTag(tag);
     if(ge) ge->setMeshSizeParametric(parametricCoord, sizes);
@@ -4133,7 +4181,7 @@ gmsh::model::mesh::setTransfiniteCurve(const int tag, const int numNodes,
                                        const std::string &meshType,
                                        const double coef)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   // for compatibility with geo files, try both tag and -tag
   for(int sig = -1; sig <= 1; sig += 2) {
     int t = sig * tag;
@@ -4152,7 +4200,7 @@ gmsh::model::mesh::setTransfiniteCurve(const int tag, const int numNodes,
     else {
       if(t > 0) {
         Msg::Error("%s does not exist", _getEntityName(1, t).c_str());
-        throw 2;
+        throw Msg::GetLastError();
       }
     }
   }
@@ -4163,11 +4211,11 @@ gmsh::model::mesh::setTransfiniteSurface(const int tag,
                                          const std::string &arrangement,
                                          const std::vector<int> &cornerTags)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GFace *gf = GModel::current()->getFaceByTag(tag);
   if(!gf) {
     Msg::Error("%s does not exist", _getEntityName(2, tag).c_str());
-    throw 2;
+    throw Msg::GetLastError();
   }
   gf->meshAttributes.method = MESH_TRANSFINITE;
   gf->meshAttributes.transfiniteArrangement =
@@ -4191,11 +4239,11 @@ GMSH_API void
 gmsh::model::mesh::setTransfiniteVolume(const int tag,
                                         const std::vector<int> &cornerTags)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GRegion *gr = GModel::current()->getRegionByTag(tag);
   if(!gr) {
     Msg::Error("%s does not exist", _getEntityName(3, tag).c_str());
-    throw 2;
+    throw Msg::GetLastError();
   }
   gr->meshAttributes.method = MESH_TRANSFINITE;
   if(cornerTags.empty() || cornerTags.size() == 6 || cornerTags.size() == 8) {
@@ -4208,39 +4256,41 @@ gmsh::model::mesh::setTransfiniteVolume(const int tag,
 
 GMSH_API void gmsh::model::mesh::setRecombine(const int dim, const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
-  if(dim != 2) { throw 2; }
-  GFace *gf = GModel::current()->getFaceByTag(tag);
-  if(!gf) {
-    Msg::Error("%s does not exist", _getEntityName(dim, tag).c_str());
-    throw 2;
+  _checkInit();
+  if(dim == 2) {
+    GFace *gf = GModel::current()->getFaceByTag(tag);
+    if(!gf) {
+      Msg::Error("%s does not exist", _getEntityName(dim, tag).c_str());
+      throw Msg::GetLastError();
+    }
+    gf->meshAttributes.recombine = 1;
+    gf->meshAttributes.recombineAngle = 45.;
   }
-  gf->meshAttributes.recombine = 1;
-  gf->meshAttributes.recombineAngle = 45.;
 }
 
 GMSH_API void gmsh::model::mesh::setSmoothing(const int dim, const int tag,
                                               const int val)
 {
-  if(!_isInitialized()) { throw -1; }
-  if(dim != 2) { throw 2; }
-  GFace *gf = GModel::current()->getFaceByTag(tag);
-  if(!gf) {
-    Msg::Error("%s does not exist", _getEntityName(dim, tag).c_str());
-    throw 2;
+  _checkInit();
+  if(dim == 2) {
+    GFace *gf = GModel::current()->getFaceByTag(tag);
+    if(!gf) {
+      Msg::Error("%s does not exist", _getEntityName(dim, tag).c_str());
+      throw Msg::GetLastError();
+    }
+    gf->meshAttributes.transfiniteSmoothing = val;
   }
-  gf->meshAttributes.transfiniteSmoothing = val;
 }
 
 GMSH_API void gmsh::model::mesh::setReverse(const int dim, const int tag,
                                             const bool val)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   if(dim == 1) {
     GEdge *ge = GModel::current()->getEdgeByTag(tag);
     if(!ge) {
       Msg::Error("%s does not exist", _getEntityName(dim, tag).c_str());
-      throw 2;
+      throw Msg::GetLastError();
     }
     ge->meshAttributes.reverseMesh = val;
   }
@@ -4248,7 +4298,7 @@ GMSH_API void gmsh::model::mesh::setReverse(const int dim, const int tag,
     GFace *gf = GModel::current()->getFaceByTag(tag);
     if(!gf) {
       Msg::Error("%s does not exist", _getEntityName(dim, tag).c_str());
-      throw 2;
+      throw Msg::GetLastError();
     }
     gf->meshAttributes.reverseMesh = val;
   }
@@ -4257,12 +4307,12 @@ GMSH_API void gmsh::model::mesh::setReverse(const int dim, const int tag,
 GMSH_API void gmsh::model::mesh::setAlgorithm(const int dim, const int tag,
                                               const int val)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   if(dim == 2) {
     GFace *gf = GModel::current()->getFaceByTag(tag);
     if(!gf) {
       Msg::Error("%s does not exist", _getEntityName(dim, tag).c_str());
-      throw 2;
+      throw Msg::GetLastError();
     }
     gf->meshAttributes.algorithm = val;
   }
@@ -4272,12 +4322,12 @@ GMSH_API void gmsh::model::mesh::setSizeFromBoundary(const int dim,
                                                      const int tag,
                                                      const int val)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   if(dim == 2) {
     GFace *gf = GModel::current()->getFaceByTag(tag);
     if(!gf) {
       Msg::Error("%s does not exist", _getEntityName(dim, tag).c_str());
-      throw 2;
+      throw Msg::GetLastError();
     }
     gf->meshAttributes.meshSizeFromBoundary = val;
   }
@@ -4286,7 +4336,7 @@ GMSH_API void gmsh::model::mesh::setSizeFromBoundary(const int dim,
 GMSH_API void gmsh::model::mesh::setCompound(const int dim,
                                              const std::vector<int> &tags)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   std::vector<GEntity *> ents;
   for(std::size_t i = 0; i < tags.size(); i++) {
     GEntity *ent = GModel::current()->getEntityByTag(dim, tags[i]);
@@ -4300,11 +4350,11 @@ GMSH_API void gmsh::model::mesh::setCompound(const int dim,
 
 GMSH_API void gmsh::model::mesh::setOutwardOrientation(const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GRegion *gr = GModel::current()->getRegionByTag(tag);
   if(!gr) {
     Msg::Error("%s does not exist", _getEntityName(3, tag).c_str());
-    throw 2;
+    throw Msg::GetLastError();
   }
   gr->setOutwardOrientationMeshConstraint();
 }
@@ -4313,19 +4363,19 @@ GMSH_API void gmsh::model::mesh::embed(const int dim,
                                        const std::vector<int> &tags,
                                        const int inDim, const int inTag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   if(inDim == 2) {
     GFace *gf = GModel::current()->getFaceByTag(inTag);
     if(!gf) {
       Msg::Error("%s does not exist", _getEntityName(2, inTag).c_str());
-      throw 2;
+      throw Msg::GetLastError();
     }
     for(std::size_t i = 0; i < tags.size(); i++) {
       if(dim == 0) {
         GVertex *gv = GModel::current()->getVertexByTag(tags[i]);
         if(!gv) {
           Msg::Error("%s does not exist", _getEntityName(0, tags[i]).c_str());
-          throw 2;
+          throw Msg::GetLastError();
         }
         gf->addEmbeddedVertex(gv);
       }
@@ -4333,7 +4383,7 @@ GMSH_API void gmsh::model::mesh::embed(const int dim,
         GEdge *ge = GModel::current()->getEdgeByTag(tags[i]);
         if(!ge) {
           Msg::Error("%s does not exist", _getEntityName(1, tags[i]).c_str());
-          throw 2;
+          throw Msg::GetLastError();
         }
         gf->addEmbeddedEdge(ge);
       }
@@ -4343,14 +4393,14 @@ GMSH_API void gmsh::model::mesh::embed(const int dim,
     GRegion *gr = GModel::current()->getRegionByTag(inTag);
     if(!gr) {
       Msg::Error("%s does not exist", _getEntityName(3, inTag).c_str());
-      throw 2;
+      throw Msg::GetLastError();
     }
     for(std::size_t i = 0; i < tags.size(); i++) {
       if(dim == 0) {
         GVertex *gv = GModel::current()->getVertexByTag(tags[i]);
         if(!gv) {
           Msg::Error("%s does not exist", _getEntityName(0, tags[i]).c_str());
-          throw 2;
+          throw Msg::GetLastError();
         }
         gr->addEmbeddedVertex(gv);
       }
@@ -4358,7 +4408,7 @@ GMSH_API void gmsh::model::mesh::embed(const int dim,
         GEdge *ge = GModel::current()->getEdgeByTag(tags[i]);
         if(!ge) {
           Msg::Error("%s does not exist", _getEntityName(1, tags[i]).c_str());
-          throw 2;
+          throw Msg::GetLastError();
         }
         gr->addEmbeddedEdge(ge);
       }
@@ -4366,7 +4416,7 @@ GMSH_API void gmsh::model::mesh::embed(const int dim,
         GFace *gf = GModel::current()->getFaceByTag(tags[i]);
         if(!gf) {
           Msg::Error("%s does not exist", _getEntityName(2, tags[i]).c_str());
-          throw 2;
+          throw Msg::GetLastError();
         }
         gr->addEmbeddedFace(gf);
       }
@@ -4377,14 +4427,14 @@ GMSH_API void gmsh::model::mesh::embed(const int dim,
 GMSH_API void gmsh::model::mesh::removeEmbedded(const vectorpair &dimTags,
                                                 const int rdim)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   for(std::size_t i = 0; i < dimTags.size(); i++) {
     int dim = dimTags[i].first, tag = dimTags[i].second;
     if(dim == 2) {
       GFace *gf = GModel::current()->getFaceByTag(tag);
       if(!gf) {
         Msg::Error("%s does not exist", _getEntityName(dim, tag).c_str());
-        throw 2;
+        throw Msg::GetLastError();
       }
       if(rdim < 0 || rdim == 1) gf->embeddedEdges().clear();
       if(rdim < 0 || rdim == 0) gf->embeddedVertices().clear();
@@ -4393,7 +4443,7 @@ GMSH_API void gmsh::model::mesh::removeEmbedded(const vectorpair &dimTags,
       GRegion *gr = GModel::current()->getRegionByTag(tag);
       if(!gr) {
         Msg::Error("%s does not exist", _getEntityName(dim, tag).c_str());
-        throw 2;
+        throw Msg::GetLastError();
       }
       if(rdim < 0 || rdim == 2) gr->embeddedFaces().clear();
       if(rdim < 0 || rdim == 1) gr->embeddedEdges().clear();
@@ -4406,32 +4456,32 @@ GMSH_API void
 gmsh::model::mesh::reorderElements(const int elementType, const int tag,
                                    const std::vector<std::size_t> &ordering)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   int dim = ElementType::getDimension(elementType);
   std::map<int, std::vector<GEntity *> > typeEnt;
   _getEntitiesForElementTypes(dim, tag, typeEnt);
   const std::vector<GEntity *> &entities(typeEnt[elementType]);
   if(entities.empty()) {
     Msg::Error("No elements to reorder");
-    throw 2;
+    throw Msg::GetLastError();
   }
   for(std::size_t i = 0; i < entities.size(); i++) {
     if(!entities[i]->reorder(elementType, ordering)) {
       Msg::Error("Could not reorder elements");
-      throw 3;
+      throw Msg::GetLastError();
     }
   }
 }
 
 GMSH_API void gmsh::model::mesh::renumberNodes()
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GModel::current()->renumberMeshVertices();
 }
 
 GMSH_API void gmsh::model::mesh::renumberElements()
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GModel::current()->renumberMeshElements();
 }
 
@@ -4440,28 +4490,28 @@ gmsh::model::mesh::setPeriodic(const int dim, const std::vector<int> &tags,
                                const std::vector<int> &tagsMaster,
                                const std::vector<double> &affineTransform)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   if(tags.size() != tagsMaster.size()) {
     Msg::Error("Incompatible number of tags and master tags for periodic mesh");
-    throw 2;
+    throw Msg::GetLastError();
   }
   if(affineTransform.size() != 16) {
     Msg::Error("Wrong number of elements in affine transformation (%d != 16)",
                (int)affineTransform.size());
-    throw 2;
+    throw Msg::GetLastError();
   }
   for(std::size_t i = 0; i < tags.size(); i++) {
     if(dim == 1) {
       GEdge *target = GModel::current()->getEdgeByTag(tags[i]);
       if(!target) {
         Msg::Error("%s does not exist", _getEntityName(dim, tags[i]).c_str());
-        throw 2;
+        throw Msg::GetLastError();
       }
       GEdge *source = GModel::current()->getEdgeByTag(tagsMaster[i]);
       if(!source) {
         Msg::Error("%s does not exist",
                    _getEntityName(dim, tagsMaster[i]).c_str());
-        throw 2;
+        throw Msg::GetLastError();
       }
       target->setMeshMaster(source, affineTransform);
     }
@@ -4469,13 +4519,13 @@ gmsh::model::mesh::setPeriodic(const int dim, const std::vector<int> &tags,
       GFace *target = GModel::current()->getFaceByTag(tags[i]);
       if(!target) {
         Msg::Error("%s does not exist", _getEntityName(dim, tags[i]).c_str());
-        throw 2;
+        throw Msg::GetLastError();
       }
       GFace *source = GModel::current()->getFaceByTag(tagsMaster[i]);
       if(!source) {
         Msg::Error("%s does not exist",
                    _getEntityName(dim, tagsMaster[i]).c_str());
-        throw 2;
+        throw Msg::GetLastError();
       }
       target->setMeshMaster(source, affineTransform);
     }
@@ -4487,11 +4537,11 @@ GMSH_API void gmsh::model::mesh::getPeriodicNodes(
   std::vector<std::size_t> &nodeTags, std::vector<std::size_t> &nodeTagsMaster,
   std::vector<double> &affineTransform, const bool includeHighOrderNodes)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GEntity *ge = GModel::current()->getEntityByTag(dim, tag);
   if(!ge) {
     Msg::Error("%s does not exist", _getEntityName(dim, tag).c_str());
-    throw 2;
+    throw Msg::GetLastError();
   }
   if(ge->getMeshMaster() != ge) {
     tagMaster = ge->getMeshMaster()->tag();
@@ -4521,7 +4571,7 @@ GMSH_API void gmsh::model::mesh::getPeriodicNodes(
 
 GMSH_API void gmsh::model::mesh::removeDuplicateNodes()
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GModel::current()->removeDuplicateMeshVertices(
     CTX::instance()->geom.tolerance);
   CTX::instance()->mesh.changed = ENT_ALL;
@@ -4532,21 +4582,21 @@ gmsh::model::mesh::classifySurfaces(const double angle, const bool boundary,
                                     const bool forReparametrization,
                                     const double curveAngle)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GModel::current()->classifySurfaces(angle, boundary, forReparametrization,
                                       curveAngle);
 }
 
 GMSH_API void gmsh::model::mesh::createGeometry(const vectorpair &dimTags)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GModel::current()->createGeometryOfDiscreteEntities(dimTags);
 }
 
 GMSH_API void gmsh::model::mesh::createTopology(const bool makeSimplyConnected,
                                                 const bool exportDiscrete)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 
   if(makeSimplyConnected) {
     GModel::current()->makeDiscreteRegionsSimplyConnected();
@@ -4564,7 +4614,7 @@ gmsh::model::mesh::computeHomology(const std::vector<int> &domainTags,
                                    const std::vector<int> &subdomainTags,
                                    const std::vector<int> &dims)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GModel::current()->addHomologyRequest("Homology", domainTags, subdomainTags,
                                         dims);
 }
@@ -4574,7 +4624,7 @@ gmsh::model::mesh::computeCohomology(const std::vector<int> &domainTags,
                                      const std::vector<int> &subdomainTags,
                                      const std::vector<int> &dims)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GModel::current()->addHomologyRequest("Cohomology", domainTags, subdomainTags,
                                         dims);
 }
@@ -4584,27 +4634,27 @@ gmsh::model::mesh::computeCohomology(const std::vector<int> &domainTags,
 GMSH_API int gmsh::model::mesh::field::add(const std::string &fieldType,
                                            const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   int outTag = tag;
 #if defined(HAVE_MESH)
   if(outTag < 0) { outTag = GModel::current()->getFields()->newId(); }
   if(!GModel::current()->getFields()->newField(outTag, fieldType)) {
     Msg::Error("Cannot add Field %i of type '%s'", outTag, fieldType.c_str());
-    throw 1;
+    throw Msg::GetLastError();
   }
 #if defined(HAVE_FLTK)
   if(FlGui::available()) FlGui::instance()->updateFields();
 #endif
 #else
   Msg::Error("Fields require the mesh module");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
   return outTag;
 }
 
 GMSH_API void gmsh::model::mesh::field::remove(const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_MESH)
   GModel::current()->getFields()->deleteField(tag);
 #if defined(HAVE_FLTK)
@@ -4612,7 +4662,7 @@ GMSH_API void gmsh::model::mesh::field::remove(const int tag)
 #endif
 #else
   Msg::Error("Fields require the mesh module");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
@@ -4638,20 +4688,22 @@ GMSH_API void gmsh::model::mesh::field::setNumber(const int tag,
                                                   const std::string &option,
                                                   const double value)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_MESH)
   FieldOption *o = _getFieldOption(tag, option);
-  if(!o) { throw 1; }
+  if(!o) {
+    throw Msg::GetLastError();
+  }
   try {
     o->numericalValue(value);
   } catch(...) {
     Msg::Error("Cannot set numerical value to option '%s' in field %i",
                option.c_str(), tag);
-    throw 1;
+    throw Msg::GetLastError();
   }
 #else
   Msg::Error("Fields require the mesh module");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
@@ -4659,20 +4711,22 @@ GMSH_API void gmsh::model::mesh::field::setString(const int tag,
                                                   const std::string &option,
                                                   const std::string &value)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_MESH)
   FieldOption *o = _getFieldOption(tag, option);
-  if(!o) { throw 1; }
+  if(!o) {
+    throw Msg::GetLastError();
+  }
   try {
     o->string(value);
   } catch(...) {
     Msg::Error("Cannot set string value to option '%s' in field %i",
                option.c_str(), tag);
-    throw 1;
+    throw Msg::GetLastError();
   }
 #else
   Msg::Error("Fields require the mesh module");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
@@ -4680,10 +4734,12 @@ GMSH_API void
 gmsh::model::mesh::field::setNumbers(const int tag, const std::string &option,
                                      const std::vector<double> &value)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_MESH)
   FieldOption *o = _getFieldOption(tag, option);
-  if(!o) { throw 1; }
+  if(!o) {
+    throw Msg::GetLastError();
+  }
   try {
     if(o->getType() == FIELD_OPTION_LIST) {
       std::list<int> vl;
@@ -4698,33 +4754,33 @@ gmsh::model::mesh::field::setNumbers(const int tag, const std::string &option,
   } catch(...) {
     Msg::Error("Cannot set numeric values to option '%s' in field %i",
                option.c_str(), tag);
-    throw 1;
+    throw Msg::GetLastError();
   }
 #else
   Msg::Error("Fields require the mesh module");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
 GMSH_API void gmsh::model::mesh::field::setAsBackgroundMesh(const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_MESH)
   GModel::current()->getFields()->setBackgroundFieldId(tag);
 #else
   Msg::Error("Fields require the mesh module");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
 GMSH_API void gmsh::model::mesh::field::setAsBoundaryLayer(const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_MESH)
   GModel::current()->getFields()->addBoundaryLayerFieldId(tag);
 #else
   Msg::Error("Fields require the mesh module");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
@@ -4734,14 +4790,14 @@ GMSH_API int gmsh::model::geo::addPoint(const double x, const double y,
                                         const double z, const double meshSize,
                                         const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   int outTag = tag;
   double xx = CTX::instance()->geom.scalingFactor * x;
   double yy = CTX::instance()->geom.scalingFactor * y;
   double zz = CTX::instance()->geom.scalingFactor * z;
   double lc = CTX::instance()->geom.scalingFactor * meshSize;
   if(!GModel::current()->getGEOInternals()->addVertex(outTag, xx, yy, zz, lc)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -4749,10 +4805,10 @@ GMSH_API int gmsh::model::geo::addPoint(const double x, const double y,
 GMSH_API int gmsh::model::geo::addLine(const int startTag, const int endTag,
                                        const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   int outTag = tag;
   if(!GModel::current()->getGEOInternals()->addLine(outTag, startTag, endTag)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -4763,11 +4819,11 @@ GMSH_API int gmsh::model::geo::addCircleArc(const int startTag,
                                             const double nx, const double ny,
                                             const double nz)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   int outTag = tag;
   if(!GModel::current()->getGEOInternals()->addCircleArc(
        outTag, startTag, centerTag, endTag, nx, ny, nz)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -4776,11 +4832,11 @@ GMSH_API int gmsh::model::geo::addEllipseArc(
   const int startTag, const int centerTag, const int majorTag, const int endTag,
   const int tag, const double nx, const double ny, const double nz)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   int outTag = tag;
   if(!GModel::current()->getGEOInternals()->addEllipseArc(
        outTag, startTag, centerTag, majorTag, endTag, nx, ny, nz)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -4788,10 +4844,10 @@ GMSH_API int gmsh::model::geo::addEllipseArc(
 GMSH_API int gmsh::model::geo::addSpline(const std::vector<int> &pointTags,
                                          const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   int outTag = tag;
   if(!GModel::current()->getGEOInternals()->addSpline(outTag, pointTags)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -4799,10 +4855,10 @@ GMSH_API int gmsh::model::geo::addSpline(const std::vector<int> &pointTags,
 GMSH_API int gmsh::model::geo::addBSpline(const std::vector<int> &pointTags,
                                           const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   int outTag = tag;
   if(!GModel::current()->getGEOInternals()->addBSpline(outTag, pointTags)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -4810,10 +4866,10 @@ GMSH_API int gmsh::model::geo::addBSpline(const std::vector<int> &pointTags,
 GMSH_API int gmsh::model::geo::addBezier(const std::vector<int> &pointTags,
                                          const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   int outTag = tag;
   if(!GModel::current()->getGEOInternals()->addBezier(outTag, pointTags)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -4821,10 +4877,10 @@ GMSH_API int gmsh::model::geo::addBezier(const std::vector<int> &pointTags,
 GMSH_API int gmsh::model::geo::addPolyline(const std::vector<int> &pointTags,
                                            const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   int outTag = tag;
   if(!GModel::current()->getGEOInternals()->addLine(outTag, pointTags)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -4833,11 +4889,11 @@ GMSH_API int
 gmsh::model::geo::addCompoundSpline(const std::vector<int> &curveTags,
                                     const int numIntervals, const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   int outTag = tag;
   if(!GModel::current()->getGEOInternals()->addCompoundSpline(outTag, curveTags,
                                                               numIntervals)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -4846,11 +4902,11 @@ GMSH_API int
 gmsh::model::geo::addCompoundBSpline(const std::vector<int> &curveTags,
                                      const int numIntervals, const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   int outTag = tag;
   if(!GModel::current()->getGEOInternals()->addCompoundBSpline(
        outTag, curveTags, numIntervals)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -4858,10 +4914,10 @@ gmsh::model::geo::addCompoundBSpline(const std::vector<int> &curveTags,
 GMSH_API int gmsh::model::geo::addCurveLoop(const std::vector<int> &curveTags,
                                             const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   int outTag = tag;
   if(!GModel::current()->getGEOInternals()->addLineLoop(outTag, curveTags)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -4869,10 +4925,10 @@ GMSH_API int gmsh::model::geo::addCurveLoop(const std::vector<int> &curveTags,
 GMSH_API int gmsh::model::geo::addPlaneSurface(const std::vector<int> &wireTags,
                                                const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   int outTag = tag;
   if(!GModel::current()->getGEOInternals()->addPlaneSurface(outTag, wireTags)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -4881,11 +4937,11 @@ GMSH_API int
 gmsh::model::geo::addSurfaceFilling(const std::vector<int> &wireTags,
                                     const int tag, const int sphereCenterTag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   int outTag = tag;
   if(!GModel::current()->getGEOInternals()->addSurfaceFilling(
        outTag, wireTags, sphereCenterTag)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -4894,11 +4950,11 @@ GMSH_API int
 gmsh::model::geo::addSurfaceLoop(const std::vector<int> &surfaceTags,
                                  const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   int outTag = tag;
   if(!GModel::current()->getGEOInternals()->addSurfaceLoop(outTag,
                                                            surfaceTags)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -4906,10 +4962,10 @@ gmsh::model::geo::addSurfaceLoop(const std::vector<int> &surfaceTags,
 GMSH_API int gmsh::model::geo::addVolume(const std::vector<int> &shellTags,
                                          const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   int outTag = tag;
   if(!GModel::current()->getGEOInternals()->addVolume(outTag, shellTags)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -4943,20 +4999,20 @@ GMSH_API void gmsh::model::geo::extrude(const vectorpair &dimTags,
                                         const std::vector<double> &heights,
                                         const bool recombine)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   outDimTags.clear();
   if(dx || dy || dz) {
     if(!GModel::current()->getGEOInternals()->extrude(
          dimTags, dx, dy, dz, outDimTags,
          _getExtrudeParams(numElements, heights, recombine))) {
-      throw 1;
+      throw Msg::GetLastError();
     }
   }
   else {
     if(!GModel::current()->getGEOInternals()->boundaryLayer(
          dimTags, outDimTags,
          _getExtrudeParams(numElements, heights, recombine))) {
-      throw 1;
+      throw Msg::GetLastError();
     }
   }
 }
@@ -4967,12 +5023,12 @@ GMSH_API void gmsh::model::geo::revolve(
   vectorpair &outDimTags, const std::vector<int> &numElements,
   const std::vector<double> &heights, const bool recombine)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   outDimTags.clear();
   if(!GModel::current()->getGEOInternals()->revolve(
        dimTags, x, y, z, ax, ay, az, angle, outDimTags,
        _getExtrudeParams(numElements, heights, recombine))) {
-    throw 1;
+    throw Msg::GetLastError();
   }
 }
 
@@ -4983,12 +5039,12 @@ GMSH_API void gmsh::model::geo::twist(
   const std::vector<int> &numElements, const std::vector<double> &heights,
   const bool recombine)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   outDimTags.clear();
   if(!GModel::current()->getGEOInternals()->twist(
        dimTags, x, y, z, dx, dy, dz, ax, ay, az, angle, outDimTags,
        _getExtrudeParams(numElements, heights, recombine))) {
-    throw 1;
+    throw Msg::GetLastError();
   }
 }
 
@@ -4996,9 +5052,9 @@ GMSH_API void gmsh::model::geo::translate(const vectorpair &dimTags,
                                           const double dx, const double dy,
                                           const double dz)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   if(!GModel::current()->getGEOInternals()->translate(dimTags, dx, dy, dz)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
 }
 
@@ -5008,10 +5064,10 @@ GMSH_API void gmsh::model::geo::rotate(const vectorpair &dimTags,
                                        const double ay, const double az,
                                        const double angle)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   if(!GModel::current()->getGEOInternals()->rotate(dimTags, x, y, z, ax, ay, az,
                                                    angle)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
 }
 
@@ -5020,9 +5076,9 @@ GMSH_API void gmsh::model::geo::dilate(const vectorpair &dimTags,
                                        const double z, const double a,
                                        const double b, const double c)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   if(!GModel::current()->getGEOInternals()->dilate(dimTags, x, y, z, a, b, c)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
 }
 
@@ -5030,9 +5086,9 @@ GMSH_API void gmsh::model::geo::mirror(const vectorpair &dimTags,
                                        const double a, const double b,
                                        const double c, const double d)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   if(!GModel::current()->getGEOInternals()->symmetry(dimTags, a, b, c, d)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
 }
 
@@ -5047,25 +5103,25 @@ GMSH_API void gmsh::model::geo::symmetrize(const vectorpair &dimTags,
 GMSH_API void gmsh::model::geo::copy(const vectorpair &dimTags,
                                      vectorpair &outDimTags)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   outDimTags.clear();
   if(!GModel::current()->getGEOInternals()->copy(dimTags, outDimTags)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
 }
 
 GMSH_API void gmsh::model::geo::remove(const vectorpair &dimTags,
                                        const bool recursive)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   if(!GModel::current()->getGEOInternals()->remove(dimTags, recursive)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
 }
 
 GMSH_API void gmsh::model::geo::removeAllDuplicates()
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GModel::current()->getGEOInternals()->removeAllDuplicates();
 }
 
@@ -5073,28 +5129,28 @@ GMSH_API void gmsh::model::geo::splitCurve(const int tag,
                                            const std::vector<int> &pointTags,
                                            std::vector<int> &curveTags)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   if(!GModel::current()->getGEOInternals()->splitCurve(tag, pointTags,
                                                        curveTags)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
 }
 
 GMSH_API int gmsh::model::geo::getMaxTag(const int dim)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   return GModel::current()->getGEOInternals()->getMaxTag(dim);
 }
 
 GMSH_API void gmsh::model::geo::setMaxTag(const int dim, const int maxTag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GModel::current()->getGEOInternals()->setMaxTag(dim, maxTag);
 }
 
 GMSH_API void gmsh::model::geo::synchronize()
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GModel::current()->getGEOInternals()->synchronize(GModel::current());
 }
 
@@ -5105,7 +5161,7 @@ gmsh::model::geo::mesh::setTransfiniteCurve(const int tag, const int nPoints,
                                             const std::string &meshType,
                                             const double coef)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   int type = (meshType == "Progression" || meshType == "Power") ?
                1 :
                (meshType == "Bump") ? 2 : 1;
@@ -5123,7 +5179,7 @@ GMSH_API void gmsh::model::geo::mesh::setTransfiniteSurface(
   const int tag, const std::string &arrangement,
   const std::vector<int> &cornerTags)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   int t = (arrangement == "Right") ?
             1 :
             (arrangement == "Left") ? -1 :
@@ -5140,36 +5196,37 @@ GMSH_API void
 gmsh::model::geo::mesh::setTransfiniteVolume(const int tag,
                                              const std::vector<int> &cornerTags)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GModel::current()->getGEOInternals()->setTransfiniteVolume(tag, cornerTags);
 }
 
 GMSH_API void gmsh::model::geo::mesh::setRecombine(const int dim, const int tag,
                                                    const double angle)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GModel::current()->getGEOInternals()->setRecombine(dim, tag, angle);
 }
 
 GMSH_API void gmsh::model::geo::mesh::setSmoothing(const int dim, const int tag,
                                                    const int val)
 {
-  if(!_isInitialized()) { throw -1; }
-  if(dim != 2) { throw 2; }
-  GModel::current()->getGEOInternals()->setSmoothing(tag, val);
+  _checkInit();
+  if(dim == 2) {
+    GModel::current()->getGEOInternals()->setSmoothing(tag, val);
+  }
 }
 
 GMSH_API void gmsh::model::geo::mesh::setReverse(const int dim, const int tag,
                                                  const bool val)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GModel::current()->getGEOInternals()->setReverseMesh(dim, tag, val);
 }
 
 GMSH_API void gmsh::model::geo::mesh::setAlgorithm(const int dim, const int tag,
                                                    const int val)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GModel::current()->getGEOInternals()->setMeshAlgorithm(dim, tag, val);
 }
 
@@ -5177,14 +5234,14 @@ GMSH_API void gmsh::model::geo::mesh::setSizeFromBoundary(const int dim,
                                                           const int tag,
                                                           const int val)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GModel::current()->getGEOInternals()->setMeshSizeFromBoundary(dim, tag, val);
 }
 
 GMSH_API void gmsh::model::geo::mesh::setSize(const vectorpair &dimTags,
                                               const double size)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   for(std::size_t i = 0; i < dimTags.size(); i++) {
     int dim = dimTags[i].first, tag = dimTags[i].second;
     GModel::current()->getGEOInternals()->setMeshSize(dim, tag, size);
@@ -5203,12 +5260,12 @@ GMSH_API int gmsh::model::occ::addPoint(const double x, const double y,
                                         const double z, const double meshSize,
                                         const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   int outTag = tag;
   if(!GModel::current()->getOCCInternals()->addVertex(outTag, x, y, z,
                                                       meshSize)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -5216,11 +5273,11 @@ GMSH_API int gmsh::model::occ::addPoint(const double x, const double y,
 GMSH_API int gmsh::model::occ::addLine(const int startTag, const int endTag,
                                        const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   int outTag = tag;
   if(!GModel::current()->getOCCInternals()->addLine(outTag, startTag, endTag)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -5229,12 +5286,12 @@ GMSH_API int gmsh::model::occ::addCircleArc(const int startTag,
                                             const int centerTag,
                                             const int endTag, const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   int outTag = tag;
   if(!GModel::current()->getOCCInternals()->addCircleArc(outTag, startTag,
                                                          centerTag, endTag)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -5244,12 +5301,12 @@ GMSH_API int gmsh::model::occ::addCircle(const double x, const double y,
                                          const int tag, const double angle1,
                                          const double angle2)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   int outTag = tag;
   if(!GModel::current()->getOCCInternals()->addCircle(outTag, x, y, z, r,
                                                       angle1, angle2)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -5259,12 +5316,12 @@ GMSH_API int gmsh::model::occ::addEllipseArc(const int startTag,
                                              const int majorTag,
                                              const int endTag, const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   int outTag = tag;
   if(!GModel::current()->getOCCInternals()->addEllipseArc(
        outTag, startTag, centerTag, majorTag, endTag)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -5275,12 +5332,12 @@ GMSH_API int gmsh::model::occ::addEllipse(const double x, const double y,
                                           const double angle1,
                                           const double angle2)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   int outTag = tag;
   if(!GModel::current()->getOCCInternals()->addEllipse(outTag, x, y, z, r1, r2,
                                                        angle1, angle2)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -5288,11 +5345,11 @@ GMSH_API int gmsh::model::occ::addEllipse(const double x, const double y,
 GMSH_API int gmsh::model::occ::addSpline(const std::vector<int> &pointTags,
                                          const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   int outTag = tag;
   if(!GModel::current()->getOCCInternals()->addSpline(outTag, pointTags)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -5302,11 +5359,11 @@ GMSH_API int gmsh::model::occ::addBSpline(
   const std::vector<double> &weights, const std::vector<double> &knots,
   const std::vector<int> &multiplicities)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   int outTag = tag;
   if(!GModel::current()->getOCCInternals()->addBSpline(
        outTag, pointTags, degree, weights, knots, multiplicities)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -5314,11 +5371,11 @@ GMSH_API int gmsh::model::occ::addBSpline(
 GMSH_API int gmsh::model::occ::addBezier(const std::vector<int> &pointTags,
                                          const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   int outTag = tag;
   if(!GModel::current()->getOCCInternals()->addBezier(outTag, pointTags)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -5326,12 +5383,12 @@ GMSH_API int gmsh::model::occ::addBezier(const std::vector<int> &pointTags,
 GMSH_API int gmsh::model::occ::addWire(const std::vector<int> &curveTags,
                                        const int tag, const bool checkClosed)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   int outTag = tag;
   if(!GModel::current()->getOCCInternals()->addWire(outTag, curveTags,
                                                     checkClosed)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -5339,11 +5396,11 @@ GMSH_API int gmsh::model::occ::addWire(const std::vector<int> &curveTags,
 GMSH_API int gmsh::model::occ::addCurveLoop(const std::vector<int> &curveTags,
                                             const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   int outTag = tag;
   if(!GModel::current()->getOCCInternals()->addLineLoop(outTag, curveTags)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -5353,12 +5410,12 @@ GMSH_API int gmsh::model::occ::addRectangle(const double x, const double y,
                                             const double dy, const int tag,
                                             const double roundedRadius)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   int outTag = tag;
   if(!GModel::current()->getOCCInternals()->addRectangle(outTag, x, y, z, dx,
                                                          dy, roundedRadius)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -5367,12 +5424,12 @@ GMSH_API int gmsh::model::occ::addDisk(const double xc, const double yc,
                                        const double zc, const double rx,
                                        const double ry, const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   int outTag = tag;
   if(!GModel::current()->getOCCInternals()->addDisk(outTag, xc, yc, zc, rx,
                                                     ry)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -5380,11 +5437,11 @@ GMSH_API int gmsh::model::occ::addDisk(const double xc, const double yc,
 GMSH_API int gmsh::model::occ::addPlaneSurface(const std::vector<int> &wireTags,
                                                const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   int outTag = tag;
   if(!GModel::current()->getOCCInternals()->addPlaneSurface(outTag, wireTags)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -5393,12 +5450,12 @@ GMSH_API int
 gmsh::model::occ::addSurfaceFilling(const int wireTag, const int tag,
                                     const std::vector<int> &pointTags)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   int outTag = tag;
   if(!GModel::current()->getOCCInternals()->addSurfaceFilling(outTag, wireTag,
                                                               pointTags)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -5407,12 +5464,12 @@ GMSH_API int gmsh::model::occ::addBSplineFilling(const int wireTag,
                                                  const int tag,
                                                  const std::string &type)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   int outTag = tag;
   if(!GModel::current()->getOCCInternals()->addBSplineFilling(outTag, wireTag,
                                                               type)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -5421,12 +5478,12 @@ GMSH_API int gmsh::model::occ::addBezierFilling(const int wireTag,
                                                 const int tag,
                                                 const std::string &type)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   int outTag = tag;
   if(!GModel::current()->getOCCInternals()->addBezierFilling(outTag, wireTag,
                                                              type)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -5438,12 +5495,12 @@ GMSH_API int gmsh::model::occ::addBSplineSurface(
   const std::vector<int> &multiplicitiesU,
   const std::vector<int> &multiplicitiesV)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   int outTag = tag;
   if(!GModel::current()->getOCCInternals()->addBSplineSurface(
        outTag, pointTags, numPointsU, degreeU, degreeV, weights, knotsU, knotsV,
        multiplicitiesU, multiplicitiesV)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -5452,11 +5509,11 @@ GMSH_API int
 gmsh::model::occ::addBezierSurface(const std::vector<int> &pointTags,
                                    const int numPointsU, const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   int outTag = tag;
   if(!GModel::current()->getOCCInternals()->addBezierSurface(outTag, pointTags,
                                                              numPointsU)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -5465,12 +5522,12 @@ GMSH_API int
 gmsh::model::occ::addSurfaceLoop(const std::vector<int> &surfaceTags,
                                  const int tag, const bool sewing)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   int outTag = tag;
   if(!GModel::current()->getOCCInternals()->addSurfaceLoop(outTag, surfaceTags,
                                                            sewing)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -5478,11 +5535,11 @@ gmsh::model::occ::addSurfaceLoop(const std::vector<int> &surfaceTags,
 GMSH_API int gmsh::model::occ::addVolume(const std::vector<int> &shellTags,
                                          const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   int outTag = tag;
   if(!GModel::current()->getOCCInternals()->addVolume(outTag, shellTags)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -5493,12 +5550,12 @@ GMSH_API int gmsh::model::occ::addSphere(const double xc, const double yc,
                                          const double angle2,
                                          const double angle3)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   int outTag = tag;
   if(!GModel::current()->getOCCInternals()->addSphere(
        outTag, xc, yc, zc, radius, angle1, angle2, angle3)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -5508,12 +5565,12 @@ GMSH_API int gmsh::model::occ::addBox(const double x, const double y,
                                       const double dy, const double dz,
                                       const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   int outTag = tag;
   if(!GModel::current()->getOCCInternals()->addBox(outTag, x, y, z, dx, dy,
                                                    dz)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -5524,12 +5581,12 @@ GMSH_API int gmsh::model::occ::addCylinder(const double x, const double y,
                                            const double r, const int tag,
                                            const double angle)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   int outTag = tag;
   if(!GModel::current()->getOCCInternals()->addCylinder(outTag, x, y, z, dx, dy,
                                                         dz, r, angle)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -5540,12 +5597,12 @@ GMSH_API int gmsh::model::occ::addCone(const double x, const double y,
                                        const double r1, const double r2,
                                        const int tag, const double angle)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   int outTag = tag;
   if(!GModel::current()->getOCCInternals()->addCone(outTag, x, y, z, dx, dy, dz,
                                                     r1, r2, angle)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -5555,12 +5612,12 @@ GMSH_API int gmsh::model::occ::addWedge(const double x, const double y,
                                         const double dy, const double dz,
                                         const int tag, const double ltx)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   int outTag = tag;
   if(!GModel::current()->getOCCInternals()->addWedge(outTag, x, y, z, dx, dy,
                                                      dz, ltx)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -5570,12 +5627,12 @@ GMSH_API int gmsh::model::occ::addTorus(const double x, const double y,
                                         const double r2, const int tag,
                                         const double angle)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   int outTag = tag;
   if(!GModel::current()->getOCCInternals()->addTorus(outTag, x, y, z, r1, r2,
                                                      angle)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
   return outTag;
 }
@@ -5584,12 +5641,12 @@ GMSH_API void gmsh::model::occ::addThruSections(
   const std::vector<int> &wireTags, vectorpair &outDimTags, const int tag,
   const bool makeSolid, const bool makeRuled, const int maxDegree)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   outDimTags.clear();
   if(!GModel::current()->getOCCInternals()->addThruSections(
        tag, wireTags, makeSolid, makeRuled, outDimTags, maxDegree)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
 }
 
@@ -5597,12 +5654,12 @@ GMSH_API void gmsh::model::occ::addThickSolid(
   const int volumeTag, const std::vector<int> &excludeSurfaceTags,
   const double offset, vectorpair &outDimTags, const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   outDimTags.clear();
   if(!GModel::current()->getOCCInternals()->addThickSolid(
        tag, volumeTag, excludeSurfaceTags, offset, outDimTags)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
 }
 
@@ -5613,13 +5670,13 @@ GMSH_API void gmsh::model::occ::extrude(const vectorpair &dimTags,
                                         const std::vector<double> &heights,
                                         const bool recombine)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   outDimTags.clear();
   if(!GModel::current()->getOCCInternals()->extrude(
        dimTags, dx, dy, dz, outDimTags,
        _getExtrudeParams(numElements, heights, recombine))) {
-    throw 1;
+    throw Msg::GetLastError();
   }
 }
 
@@ -5629,13 +5686,13 @@ GMSH_API void gmsh::model::occ::revolve(
   vectorpair &outDimTags, const std::vector<int> &numElements,
   const std::vector<double> &heights, const bool recombine)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   outDimTags.clear();
   if(!GModel::current()->getOCCInternals()->revolve(
        dimTags, x, y, z, ax, ay, az, angle, outDimTags,
        _getExtrudeParams(numElements, heights, recombine))) {
-    throw 1;
+    throw Msg::GetLastError();
   }
 }
 
@@ -5643,12 +5700,12 @@ GMSH_API void gmsh::model::occ::addPipe(const vectorpair &dimTags,
                                         const int wireTag,
                                         vectorpair &outDimTags)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   outDimTags.clear();
   if(!GModel::current()->getOCCInternals()->addPipe(dimTags, wireTag,
                                                     outDimTags)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
 }
 
@@ -5658,12 +5715,12 @@ GMSH_API void gmsh::model::occ::fillet(const std::vector<int> &volumeTags,
                                        vectorpair &outDimTags,
                                        const bool removeVolume)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   outDimTags.clear();
   if(!GModel::current()->getOCCInternals()->fillet(volumeTags, curveTags, radii,
                                                    outDimTags, removeVolume)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
 }
 
@@ -5674,13 +5731,13 @@ GMSH_API void gmsh::model::occ::chamfer(const std::vector<int> &volumeTags,
                                         vectorpair &outDimTags,
                                         const bool removeVolume)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   outDimTags.clear();
   if(!GModel::current()->getOCCInternals()->chamfer(volumeTags, curveTags,
                                                     surfaceTags, distances,
                                                     outDimTags, removeVolume)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
 }
 
@@ -5691,14 +5748,14 @@ GMSH_API void gmsh::model::occ::fuse(const vectorpair &objectDimTags,
                                      const int tag, const bool removeObject,
                                      const bool removeTool)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   outDimTags.clear();
   outDimTagsMap.clear();
   if(!GModel::current()->getOCCInternals()->booleanUnion(
        tag, objectDimTags, toolDimTags, outDimTags, outDimTagsMap, removeObject,
        removeTool)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
 }
 
@@ -5707,14 +5764,14 @@ GMSH_API void gmsh::model::occ::intersect(
   vectorpair &outDimTags, std::vector<vectorpair> &outDimTagsMap, const int tag,
   const bool removeObject, const bool removeTool)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   outDimTags.clear();
   outDimTagsMap.clear();
   if(!GModel::current()->getOCCInternals()->booleanIntersection(
        tag, objectDimTags, toolDimTags, outDimTags, outDimTagsMap, removeObject,
        removeTool)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
 }
 
@@ -5725,14 +5782,14 @@ GMSH_API void gmsh::model::occ::cut(const vectorpair &objectDimTags,
                                     const int tag, const bool removeObject,
                                     const bool removeTool)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   outDimTags.clear();
   outDimTagsMap.clear();
   if(!GModel::current()->getOCCInternals()->booleanDifference(
        tag, objectDimTags, toolDimTags, outDimTags, outDimTagsMap, removeObject,
        removeTool)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
 }
 
@@ -5743,14 +5800,14 @@ GMSH_API void gmsh::model::occ::fragment(const vectorpair &objectDimTags,
                                          const int tag, const bool removeObject,
                                          const bool removeTool)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   outDimTags.clear();
   outDimTagsMap.clear();
   if(!GModel::current()->getOCCInternals()->booleanFragments(
        tag, objectDimTags, toolDimTags, outDimTags, outDimTagsMap, removeObject,
        removeTool)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
 }
 
@@ -5758,10 +5815,10 @@ GMSH_API void gmsh::model::occ::translate(const vectorpair &dimTags,
                                           const double dx, const double dy,
                                           const double dz)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   if(!GModel::current()->getOCCInternals()->translate(dimTags, dx, dy, dz)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
 }
 
@@ -5771,11 +5828,11 @@ GMSH_API void gmsh::model::occ::rotate(const vectorpair &dimTags,
                                        const double ay, const double az,
                                        const double angle)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   if(!GModel::current()->getOCCInternals()->rotate(dimTags, x, y, z, ax, ay, az,
                                                    angle)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
 }
 
@@ -5784,10 +5841,10 @@ GMSH_API void gmsh::model::occ::dilate(const vectorpair &dimTags,
                                        const double z, const double a,
                                        const double b, const double c)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   if(!GModel::current()->getOCCInternals()->dilate(dimTags, x, y, z, a, b, c)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
 }
 
@@ -5795,10 +5852,10 @@ GMSH_API void gmsh::model::occ::mirror(const vectorpair &dimTags,
                                        const double a, const double b,
                                        const double c, const double d)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   if(!GModel::current()->getOCCInternals()->symmetry(dimTags, a, b, c, d)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
 }
 
@@ -5812,35 +5869,37 @@ GMSH_API void gmsh::model::occ::symmetrize(const vectorpair &dimTags,
 GMSH_API void gmsh::model::occ::affineTransform(const vectorpair &dimTags,
                                                 const std::vector<double> &a)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
-  if(!GModel::current()->getOCCInternals()->affine(dimTags, a)) { throw 1; }
+  if(!GModel::current()->getOCCInternals()->affine(dimTags, a)) {
+    throw Msg::GetLastError();
+  }
 }
 
 GMSH_API void gmsh::model::occ::copy(const vectorpair &dimTags,
                                      vectorpair &outDimTags)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   outDimTags.clear();
   if(!GModel::current()->getOCCInternals()->copy(dimTags, outDimTags)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
 }
 
 GMSH_API void gmsh::model::occ::remove(const vectorpair &dimTags,
                                        const bool recursive)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   if(!GModel::current()->getOCCInternals()->remove(dimTags, recursive)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
 }
 
 GMSH_API void gmsh::model::occ::removeAllDuplicates()
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   GModel::current()->getOCCInternals()->removeAllDuplicates();
 }
@@ -5850,13 +5909,13 @@ GMSH_API void gmsh::model::occ::healShapes(
   const bool fixDegenerated, const bool fixSmallEdges, const bool fixSmallFaces,
   const bool sewFaces, const bool makeSolids)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   outDimTags.clear();
   if(!GModel::current()->getOCCInternals()->healShapes(
        inDimTags, outDimTags, tolerance, fixDegenerated, fixSmallEdges,
        fixSmallFaces, sewFaces, makeSolids)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
 }
 
@@ -5865,38 +5924,38 @@ GMSH_API void gmsh::model::occ::importShapes(const std::string &fileName,
                                              const bool highestDimOnly,
                                              const std::string &format)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   outDimTags.clear();
   if(!GModel::current()->getOCCInternals()->importShapes(
        fileName, highestDimOnly, outDimTags, format)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
 }
 
 GMSH_API void gmsh::model::occ::importShapesNativePointer(
   const void *shape, vectorpair &outDimTags, const bool highestDimOnly)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   outDimTags.clear();
 #if defined(HAVE_OCC)
   if(!GModel::current()->getOCCInternals()->importShapes(
        static_cast<const TopoDS_Shape *>(shape), highestDimOnly, outDimTags)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
 #else
   Msg::Error("Gmsh requires OpenCASCADE to import native shape");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
 GMSH_API void gmsh::model::occ::getEntities(vectorpair &dimTags, const int dim)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   if(!GModel::current()->getOCCInternals()->getEntities(dimTags, dim)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
 }
 
@@ -5904,11 +5963,11 @@ GMSH_API void gmsh::model::occ::getEntitiesInBoundingBox(
   const double xmin, const double ymin, const double zmin, const double xmax,
   const double ymax, const double zmax, vectorpair &dimTags, const int dim)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   dimTags.clear();
   if(!GModel::current()->getOCCInternals()->getEntitiesInBoundingBox(
        xmin, ymin, zmin, xmax, ymax, zmax, dimTags, dim)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
 }
 
@@ -5917,60 +5976,60 @@ GMSH_API void gmsh::model::occ::getBoundingBox(const int dim, const int tag,
                                                double &zmin, double &xmax,
                                                double &ymax, double &zmax)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   if(!GModel::current()->getOCCInternals()->getBoundingBox(
        dim, tag, xmin, ymin, zmin, xmax, ymax, zmax)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
 }
 
 GMSH_API void gmsh::model::occ::getMass(const int dim, const int tag,
                                         double &mass)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   if(!GModel::current()->getOCCInternals()->getMass(dim, tag, mass)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
 }
 
 GMSH_API void gmsh::model::occ::getCenterOfMass(const int dim, const int tag,
                                                 double &x, double &y, double &z)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   if(!GModel::current()->getOCCInternals()->getCenterOfMass(dim, tag, x, y,
                                                             z)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
 }
 
 GMSH_API void gmsh::model::occ::getMatrixOfInertia(const int dim, const int tag,
                                                    std::vector<double> &m)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   if(!GModel::current()->getOCCInternals()->getMatrixOfInertia(dim, tag, m)) {
-    throw 1;
+    throw Msg::GetLastError();
   }
 }
 
 GMSH_API int gmsh::model::occ::getMaxTag(const int dim)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   return GModel::current()->getOCCInternals()->getMaxTag(dim);
 }
 
 GMSH_API void gmsh::model::occ::setMaxTag(const int dim, const int maxTag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GModel::current()->getOCCInternals()->setMaxTag(dim, maxTag);
 }
 
 GMSH_API void gmsh::model::occ::synchronize()
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   GModel::current()->getOCCInternals()->synchronize(GModel::current());
 }
@@ -5980,7 +6039,7 @@ GMSH_API void gmsh::model::occ::synchronize()
 GMSH_API void gmsh::model::occ::mesh::setSize(const vectorpair &dimTags,
                                               const double size)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _createOcc();
   for(std::size_t i = 0; i < dimTags.size(); i++) {
     int dim = dimTags[i].first, tag = dimTags[i].second;
@@ -5992,7 +6051,7 @@ GMSH_API void gmsh::model::occ::mesh::setSize(const vectorpair &dimTags,
 
 GMSH_API int gmsh::view::add(const std::string &name, const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_POST)
   PView *view = new PView(tag);
   view->getData()->setName(name);
@@ -6002,18 +6061,18 @@ GMSH_API int gmsh::view::add(const std::string &name, const int tag)
   return view->getTag();
 #else
   Msg::Error("Views require the post-processing module");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
 GMSH_API void gmsh::view::remove(const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_POST)
   PView *view = PView::getViewByTag(tag);
   if(!view) {
     Msg::Error("Unknown view with tag %d", tag);
-    throw 2;
+    throw Msg::GetLastError();
   }
   delete view;
 #if defined(HAVE_FLTK)
@@ -6021,36 +6080,36 @@ GMSH_API void gmsh::view::remove(const int tag)
 #endif
 #else
   Msg::Error("Views require the post-processing module");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
 GMSH_API int gmsh::view::getIndex(const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_POST)
   PView *view = PView::getViewByTag(tag);
   if(!view) {
     Msg::Error("Unknown view with tag %d", tag);
-    throw 2;
+    throw Msg::GetLastError();
   }
   return view->getIndex();
 #else
   Msg::Error("Views require the post-processing module");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
 GMSH_API void gmsh::view::getTags(std::vector<int> &tags)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_POST)
   tags.clear();
   for(std::size_t i = 0; i < PView::list.size(); i++)
     tags.push_back(PView::list[i]->getTag());
 #else
   Msg::Error("Views require the post-processing module");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
@@ -6065,14 +6124,14 @@ _addModelData(const int tag, const int step, const std::string &modelName,
   PView *view = PView::getViewByTag(tag);
   if(!view) {
     Msg::Error("Unknown view with tag %d", tag);
-    throw 2;
+    throw Msg::GetLastError();
   }
   GModel *model = GModel::current();
   if(modelName.size()) {
     model = GModel::findByName(modelName);
     if(!model) {
       Msg::Error("Unknown model '%s'", modelName.c_str());
-      throw 2;
+      throw Msg::GetLastError();
     }
   }
   PViewDataGModel *d = dynamic_cast<PViewDataGModel *>(view->getData());
@@ -6092,7 +6151,7 @@ _addModelData(const int tag, const int step, const std::string &modelName,
       type = PViewDataGModel::BeamData;
     else {
       Msg::Error("Unknown type of view to add '%s'", dataType.c_str());
-      throw 2;
+      throw Msg::GetLastError();
     }
     d = new PViewDataGModel(type);
     d->setName(name);
@@ -6101,7 +6160,7 @@ _addModelData(const int tag, const int step, const std::string &modelName,
   }
   if(!d->addData(model, tags, data, step, time, partition, numComponents)) {
     Msg::Error("Could not add model data");
-    throw 2;
+    throw Msg::GetLastError();
   }
   if(view->getOptions()->adaptVisualizationGrid)
     d->initAdaptiveData(view->getOptions()->timeStep,
@@ -6109,7 +6168,7 @@ _addModelData(const int tag, const int step, const std::string &modelName,
                         view->getOptions()->targetError);
 #else
   Msg::Error("Views require the post-processing module");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
@@ -6119,10 +6178,10 @@ GMSH_API void gmsh::view::addModelData(
   const std::vector<std::vector<double> > &data, const double time,
   const int numComponents, const int partition)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   if(tags.size() != data.size()) {
     Msg::Error("Incompatible number of tags and data");
-    throw 2;
+    throw Msg::GetLastError();
   }
   _addModelData(tag, step, modelName, dataType, tags, data, time, numComponents,
                 partition);
@@ -6134,7 +6193,7 @@ GMSH_API void gmsh::view::addHomogeneousModelData(
   const std::vector<double> &data, const double time, const int numComponents,
   const int partition)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   _addModelData(tag, step, modelName, dataType, tags, data, time, numComponents,
                 partition);
 }
@@ -6145,11 +6204,11 @@ static stepData<double> *_getModelData(const int tag, const int step,
                                        double &time, int &numComponents,
                                        int &numEnt, int &maxMult)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   PView *view = PView::getViewByTag(tag);
   if(!view) {
     Msg::Error("Unknown view with tag %d", tag);
-    throw 2;
+    throw Msg::GetLastError();
   }
   PViewDataGModel *d = dynamic_cast<PViewDataGModel *>(view->getData());
   if(!d) {
@@ -6172,7 +6231,7 @@ static stepData<double> *_getModelData(const int tag, const int step,
   if(!s) {
     Msg::Error("View with tag %d does not contain model data for step %d", tag,
                step);
-    throw 2;
+    throw Msg::GetLastError();
   }
   time = s->getTime();
   numComponents = s->getNumComponents();
@@ -6194,7 +6253,7 @@ GMSH_API void gmsh::view::getModelData(const int tag, const int step,
                                        std::vector<std::vector<double> > &data,
                                        double &time, int &numComponents)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   tags.clear();
   data.clear();
 #if defined(HAVE_POST)
@@ -6217,7 +6276,7 @@ GMSH_API void gmsh::view::getModelData(const int tag, const int step,
   }
 #else
   Msg::Error("Views require the post-processing module");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
@@ -6227,7 +6286,7 @@ GMSH_API void gmsh::view::getHomogeneousModelData(const int tag, const int step,
                                                   std::vector<double> &data,
                                                   double &time, int &numComponents)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   tags.clear();
   data.clear();
 #if defined(HAVE_POST)
@@ -6251,7 +6310,7 @@ GMSH_API void gmsh::view::getHomogeneousModelData(const int tag, const int step,
   }
 #else
   Msg::Error("Views require the post-processing module");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
@@ -6262,7 +6321,7 @@ GMSH_API void gmshViewGetModelData(const int tag, const int step,
                                    size_t **data_n, size_t *data_nn,
                                    double *time, int *numComponents, int *ierr)
 {
-  if(!_isInitialized()) {
+  if(!_isInit()) {
     if(ierr) *ierr = -1;
     return;
   }
@@ -6335,12 +6394,12 @@ GMSH_API void gmsh::view::addListData(const int tag,
                                       const int numElements,
                                       const std::vector<double> &data)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_POST)
   PView *view = PView::getViewByTag(tag);
   if(!view) {
     Msg::Error("Unknown view with tag %d", tag);
-    throw 2;
+    throw Msg::GetLastError();
   }
   PViewDataList *d = dynamic_cast<PViewDataList *>(view->getData());
   if(!d) { // change the view type
@@ -6361,10 +6420,10 @@ GMSH_API void gmsh::view::addListData(const int tag,
     }
   }
   Msg::Error("Unknown data type for list import");
-  throw 2;
+  throw Msg::GetLastError();
 #else
   Msg::Error("Views require the post-processing module");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
@@ -6373,12 +6432,12 @@ GMSH_API void gmsh::view::getListData(const int tag,
                                       std::vector<int> &numElements,
                                       std::vector<std::vector<double> > &data)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_POST)
   PView *view = PView::getViewByTag(tag);
   if(!view) {
     Msg::Error("Unknown view with tag %d", tag);
-    throw 2;
+    throw Msg::GetLastError();
   }
   PViewDataList *d = dynamic_cast<PViewDataList *>(view->getData());
   if(!d) {
@@ -6400,7 +6459,7 @@ GMSH_API void gmsh::view::getListData(const int tag,
   }
 #else
   Msg::Error("Views require the post-processing module");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
@@ -6432,12 +6491,12 @@ gmsh::view::addListDataString(const int tag, const std::vector<double> &coord,
                               const std::vector<std::string> &data,
                               const std::vector<std::string> &style)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_POST)
   PView *view = PView::getViewByTag(tag);
   if(!view) {
     Msg::Error("Unknown view with tag %d", tag);
-    throw 2;
+    throw Msg::GetLastError();
   }
   PViewDataList *d = dynamic_cast<PViewDataList *>(view->getData());
   if(!d) { // change the view type
@@ -6476,7 +6535,7 @@ gmsh::view::addListDataString(const int tag, const std::vector<double> &coord,
   d->finalize();
 #else
   Msg::Error("Views require the post-processing module");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
@@ -6485,12 +6544,12 @@ GMSH_API void gmsh::view::getListDataStrings(const int tag, const int dim,
                                              std::vector<std::string> &data,
                                              std::vector<std::string> &style)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_POST)
   PView *view = PView::getViewByTag(tag);
   if(!view) {
     Msg::Error("Unknown view with tag %d", tag);
-    throw 2;
+    throw Msg::GetLastError();
   }
   PViewDataList *d = dynamic_cast<PViewDataList *>(view->getData());
   if(!d) {
@@ -6537,19 +6596,19 @@ GMSH_API void gmsh::view::getListDataStrings(const int tag, const int dim,
   }
 #else
   Msg::Error("Views require the post-processing module");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
 GMSH_API int gmsh::view::addAlias(const int refTag, const bool copyOptions,
                                   const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_POST)
   PView *ref = PView::getViewByTag(refTag);
   if(!ref) {
     Msg::Error("Unknown view with tag %d", refTag);
-    throw 2;
+    throw Msg::GetLastError();
   }
   PView *view = new PView(ref, copyOptions, tag);
 #if defined(HAVE_FLTK)
@@ -6558,23 +6617,23 @@ GMSH_API int gmsh::view::addAlias(const int refTag, const bool copyOptions,
   return view->getTag();
 #else
   Msg::Error("Views require the post-processing module");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
 GMSH_API void gmsh::view::copyOptions(const int refTag, const int tag)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_POST)
   PView *ref = PView::getViewByTag(refTag);
   if(!ref) {
     Msg::Error("Unknown view with tag %d", refTag);
-    throw 2;
+    throw Msg::GetLastError();
   }
   PView *view = PView::getViewByTag(tag);
   if(!view) {
     Msg::Error("Unknown view with tag %d", tag);
-    throw 2;
+    throw Msg::GetLastError();
   }
   view->setOptions(ref->getOptions());
 #if defined(HAVE_FLTK)
@@ -6582,7 +6641,7 @@ GMSH_API void gmsh::view::copyOptions(const int refTag, const int tag)
 #endif
 #else
   Msg::Error("Views require the post-processing module");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
@@ -6590,7 +6649,7 @@ GMSH_API void gmsh::view::combine(const std::string &what,
                                   const std::string &how, const bool remove,
                                   const bool copyOptions)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_POST)
   bool time = (what == "steps") ? true : false; // "elements"
   int ihow = (how == "all") ? 1 : (how == "name") ? 2 : 0; // "visible"
@@ -6600,7 +6659,7 @@ GMSH_API void gmsh::view::combine(const std::string &what,
 #endif
 #else
   Msg::Error("Views require the post-processing module");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
@@ -6612,15 +6671,18 @@ GMSH_API void gmsh::view::probe(const int tag, const double x, const double y,
                                 const std::vector<double> &yElemCoord,
                                 const std::vector<double> &zElemCoord)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_POST)
   PView *view = PView::getViewByTag(tag);
   if(!view) {
     Msg::Error("Unknown view with tag %d", tag);
-    throw 2;
+    throw Msg::GetLastError();
   }
   PViewData *data = view->getData();
-  if(!data) { throw 2; }
+  if(!data) {
+    Msg::Error("No data in view %d", tag);
+    throw Msg::GetLastError();
+  }
   value.clear();
   std::vector<double> val(9 * data->getNumTimeSteps());
   bool found = false;
@@ -6661,24 +6723,24 @@ GMSH_API void gmsh::view::probe(const int tag, const double x, const double y,
   if(found) value.insert(value.end(), val.begin(), val.end());
 #else
   Msg::Error("Views require the post-processing module");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
 GMSH_API void gmsh::view::write(const int tag, const std::string &fileName,
                                 const bool append)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_POST)
   PView *view = PView::getViewByTag(tag);
   if(!view) {
     Msg::Error("Unknown view with tag %d", tag);
-    throw 2;
+    throw Msg::GetLastError();
   }
   view->write(fileName, 10, append);
 #else
   Msg::Error("Views require the post-processing module");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
@@ -6688,17 +6750,17 @@ GMSH_API void gmsh::plugin::setNumber(const std::string &name,
                                       const std::string &option,
                                       const double value)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_PLUGINS)
   try {
     PluginManager::instance()->setPluginOption(name, option, value);
   } catch(...) {
     Msg::Error("Unknown plugin or plugin option");
-    throw 2;
+    throw Msg::GetLastError();
   }
 #else
   Msg::Error("Views require the post-processing and plugin modules");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
@@ -6706,33 +6768,33 @@ GMSH_API void gmsh::plugin::setString(const std::string &name,
                                       const std::string &option,
                                       const std::string &value)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_PLUGINS)
   try {
     PluginManager::instance()->setPluginOption(name, option, value);
   } catch(...) {
     Msg::Error("Unknown plugin or plugin option");
-    throw 2;
+    throw Msg::GetLastError();
   }
 #else
   Msg::Error("Views require the post-processing and plugin modules");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
 GMSH_API void gmsh::plugin::run(const std::string &name)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_PLUGINS)
   try {
     PluginManager::instance()->action(name, "Run", 0);
   } catch(...) {
     Msg::Error("Unknown plugin or plugin action");
-    throw 2;
+    throw Msg::GetLastError();
   }
 #else
   Msg::Error("Views require the post-processing and plugin modules");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
@@ -6755,25 +6817,25 @@ static void error_handler(const char *fmt, ...)
   vsnprintf(str, sizeof(str), fmt, args);
   va_end(args);
   Msg::Error("%s (FLTK internal error)", str);
-  throw -1;
+  throw Msg::GetLastError();
 }
 
 GMSH_API void gmsh::fltk::initialize()
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_FLTK)
   FlGui::instance(_argc, _argv, false, error_handler);
   FlGui::setFinishedProcessingCommandLine();
   FlGui::check(true);
 #else
   Msg::Error("Fltk not available");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
 GMSH_API int gmsh::fltk::isAvailable()
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_FLTK)
   return FlGui::available() ? 1 : 0;
 #else
@@ -6783,7 +6845,7 @@ GMSH_API int gmsh::fltk::isAvailable()
 
 GMSH_API void gmsh::fltk::wait(const double time)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_FLTK)
   if(!FlGui::available()) FlGui::instance(_argc, _argv, false, error_handler);
   if(time >= 0)
@@ -6792,64 +6854,64 @@ GMSH_API void gmsh::fltk::wait(const double time)
     FlGui::wait(true);
 #else
   Msg::Error("Fltk not available");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
 GMSH_API void gmsh::fltk::lock()
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_FLTK)
   FlGui::lock();
 #else
   Msg::Error("Fltk not available");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
 GMSH_API void gmsh::fltk::unlock()
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_FLTK)
   FlGui::unlock();
 #else
   Msg::Error("Fltk not available");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
 GMSH_API void gmsh::fltk::update()
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_FLTK)
   if(!FlGui::available()) FlGui::instance(_argc, _argv, false, error_handler);
   FlGui::instance()->updateViews(true, true);
 #else
   Msg::Error("Fltk not available");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
 GMSH_API void gmsh::fltk::awake(const std::string &action)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_FLTK)
   FlGui::awake(action);
 #else
   Msg::Error("Fltk not available");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
 GMSH_API void gmsh::fltk::run()
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_FLTK)
   if(!FlGui::available()) FlGui::instance(_argc, _argv, false, error_handler);
   FlGui::instance()->run(); // this calls draw() once
 #else
   Msg::Error("Fltk not available");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
@@ -6869,7 +6931,7 @@ static int selectionCode(char val)
 
 GMSH_API int gmsh::fltk::selectEntities(vectorpair &dimTags, const int dim)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   dimTags.clear();
 #if defined(HAVE_FLTK)
   if(!FlGui::available()) FlGui::instance(_argc, _argv, false, error_handler);
@@ -6901,7 +6963,7 @@ GMSH_API int gmsh::fltk::selectEntities(vectorpair &dimTags, const int dim)
 
 GMSH_API int gmsh::fltk::selectElements(std::vector<std::size_t> &elementTags)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   elementTags.clear();
 #if defined(HAVE_FLTK)
   if(!FlGui::available()) FlGui::instance(_argc, _argv, false, error_handler);
@@ -6920,7 +6982,7 @@ GMSH_API int gmsh::fltk::selectElements(std::vector<std::size_t> &elementTags)
 
 GMSH_API int gmsh::fltk::selectViews(std::vector<int> &viewTags)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   viewTags.clear();
 #if defined(HAVE_FLTK)
   if(!FlGui::available()) FlGui::instance(_argc, _argv, false, error_handler);
@@ -6938,7 +7000,7 @@ GMSH_API int gmsh::fltk::selectViews(std::vector<int> &viewTags)
 GMSH_API void gmsh::onelab::set(const std::string &data,
                                 const std::string &format)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_ONELAB)
   if(format == "json") {
     if(!::onelab::server::instance()->fromJSON(data))
@@ -6948,14 +7010,14 @@ GMSH_API void gmsh::onelab::set(const std::string &data,
     Msg::Error("Unknown data format");
 #else
   Msg::Error("ONELAB not available");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
 GMSH_API void gmsh::onelab::get(std::string &data, const std::string &name,
                                 const std::string &format)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_ONELAB)
   data.clear();
   if(name.empty()) {
@@ -6986,14 +7048,14 @@ GMSH_API void gmsh::onelab::get(std::string &data, const std::string &name,
   }
 #else
   Msg::Error("ONELAB not available");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
 GMSH_API void gmsh::onelab::setNumber(const std::string &name,
                                       const std::vector<double> &value)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_ONELAB)
   ::onelab::number p(name);
   std::vector< ::onelab::number> ps;
@@ -7003,14 +7065,14 @@ GMSH_API void gmsh::onelab::setNumber(const std::string &name,
   ::onelab::server::instance()->set(p);
 #else
   Msg::Error("ONELAB not available");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
 GMSH_API void gmsh::onelab::getNumber(const std::string &name,
                                       std::vector<double> &value)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_ONELAB)
   value.clear();
   std::vector< ::onelab::number> ps;
@@ -7018,14 +7080,14 @@ GMSH_API void gmsh::onelab::getNumber(const std::string &name,
   if(ps.size()) value = ps[0].getValues();
 #else
   Msg::Error("ONELAB not available");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
 GMSH_API void gmsh::onelab::setString(const std::string &name,
                                       const std::vector<std::string> &value)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_ONELAB)
   ::onelab::string p(name);
   std::vector< ::onelab::string> ps;
@@ -7035,14 +7097,14 @@ GMSH_API void gmsh::onelab::setString(const std::string &name,
   ::onelab::server::instance()->set(p);
 #else
   Msg::Error("ONELAB not available");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
 GMSH_API void gmsh::onelab::getString(const std::string &name,
                                       std::vector<std::string> &value)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_ONELAB)
   value.clear();
   std::vector< ::onelab::string> ps;
@@ -7050,25 +7112,25 @@ GMSH_API void gmsh::onelab::getString(const std::string &name,
   if(ps.size()) value = ps[0].getValues();
 #else
   Msg::Error("ONELAB not available");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
 GMSH_API void gmsh::onelab::clear(const std::string &name)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_ONELAB)
   ::onelab::server::instance()->clear(name);
 #else
   Msg::Error("ONELAB not available");
-  throw -1;
+  throw Msg::GetLastError();
 #endif
 }
 
 GMSH_API void gmsh::onelab::run(const std::string &name,
                                 const std::string &command)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
 #if defined(HAVE_ONELAB)
   onelabUtils::runClient(name, command);
 #endif
@@ -7079,7 +7141,7 @@ GMSH_API void gmsh::onelab::run(const std::string &name,
 GMSH_API void gmsh::logger::write(const std::string &message,
                                   const std::string &level)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   if(level == "error")
     Msg::Error("%s", message.c_str());
   else if(level == "warning")
@@ -7103,7 +7165,7 @@ public:
 
 GMSH_API void gmsh::logger::start()
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GmshMessage *msg = Msg::GetCallback();
   if(msg) { Msg::Warning("Logger already started - ignoring"); }
   else {
@@ -7114,7 +7176,7 @@ GMSH_API void gmsh::logger::start()
 
 GMSH_API void gmsh::logger::get(std::vector<std::string> &log)
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   apiMsg *msg = dynamic_cast<apiMsg *>(Msg::GetCallback());
   if(msg) { msg->get(log); }
   else {
@@ -7124,7 +7186,7 @@ GMSH_API void gmsh::logger::get(std::vector<std::string> &log)
 
 GMSH_API void gmsh::logger::stop()
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   GmshMessage *msg = Msg::GetCallback();
   if(msg) {
     delete msg;
@@ -7137,12 +7199,18 @@ GMSH_API void gmsh::logger::stop()
 
 GMSH_API double gmsh::logger::getWallTime()
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   return TimeOfDay();
 }
 
 GMSH_API double gmsh::logger::getCpuTime()
 {
-  if(!_isInitialized()) { throw -1; }
+  _checkInit();
   return Cpu();
 }
+
+GMSH_API void gmsh::logger::getLastError(std::string &error)
+{
+  _checkInit();
+  error = Msg::GetLastError();
+}
diff --git a/api/GenApi.py b/api/GenApi.py
index a429ed4025..12df99eaed 100644
--- a/api/GenApi.py
+++ b/api/GenApi.py
@@ -1278,8 +1278,8 @@ class API:
                     fc.write(cpp_namespace + name + "(" +
                              ", ".join(list((a.c_arg for a in args))) + ");\n")
                     fc.write("".join((a.c_post for a in args)))
-                    fc.write("  }\n  catch(int api_ierr_){\n    " +
-                             "if(ierr) *ierr = api_ierr_;\n  }\n")
+                    fc.write("  }\n  catch(const std::string &api_error_){\n    " +
+                             "if(ierr) *ierr = 1;\n  }\n")
                     if rtype:
                         fc.write("  return result_api_;\n")
                     fc.write("}\n\n")
@@ -1309,7 +1309,10 @@ class API:
                     fcwrap.write(", &ierr);\n")
                 else:
                     fcwrap.write("&ierr);\n")
-                fcwrap.write(indent + "  " + "if(ierr) throw ierr;\n")
+                if name == 'getLastError':
+                    fcwrap.write(indent + "  " + 'if(ierr) throw "Could not get last error";\n')
+                else:
+                    fcwrap.write(indent + "  " + "if(ierr) throwLastError();\n")
                 for a in args:
                     if a.cwrap_post:
                         fcwrap.write(indent + "  " + a.cwrap_post)
@@ -1344,6 +1347,16 @@ class API:
                     s = cwrap_utils.format(ns, "inline ").split('\n')
                     for line in s:
                         fcwrap.write("  " + line + "\n")
+                    fcwrap.write("  inline void throwLastError()\n")
+                    fcwrap.write("  {\n")
+                    fcwrap.write('     int ierr = 0;\n')
+                    fcwrap.write('     char *api_error_;\n')
+                    fcwrap.write('     gmshLoggerGetLastError(&api_error_, &ierr);\n')
+                    fcwrap.write('     if(ierr) throw "Could not get last error";\n');
+                    fcwrap.write('     std::string error = std::string(api_error_);\n')
+                    fcwrap.write('     gmshFree(api_error_);\n')
+                    fcwrap.write('     throw error;\n')
+                    fcwrap.write("  }\n\n")
                     fcwrap.write("}\n\n")
                     for module in self.modules:
                         write_module(module, "", "", "")
@@ -1379,7 +1392,7 @@ class API:
             for a in args:
                 if a.python_pre: f.write(indent + a.python_pre + "\n")
             f.write(indent + "ierr = c_int()\n")
-            f.write(indent + "api__result__ = " if (
+            f.write(indent + "api_result_ = " if (
                 (rtype is oint) or (rtype is odouble)) else (indent))
             c_name = c_mpath + name[0].upper() + name[1:]
             f.write("lib." + c_name + "(\n    " + indent +
@@ -1389,11 +1402,11 @@ class API:
             if name == "finalize": # special case for finalize() function
                 f.write(indent + "signal.signal(signal.SIGINT, oldsig)\n")
             f.write(indent + "if ierr.value != 0:\n")
-            f.write(indent + "    raise ValueError(\n")
-            f.write(indent + '        "' + c_name +
-                    ' returned non-zero error code: ",\n')
-            f.write(indent + "        ierr.value)\n")
-            r = (["api__result__"]) if rtype else []
+            if name == "getLastError": # special case for getLastError() function
+                f.write(indent + "    raise Exception('Could not get last error')\n")
+            else:
+                f.write(indent + "    raise Exception(logger.getLastError())\n")
+            r = (["api_result_"]) if rtype else []
             r += list((o.python_return for o in oargs))
             if len(r) != 0:
                 if len(r) == 1:
@@ -1455,7 +1468,7 @@ class API:
             for a in args:
                 if a.julia_pre: f.write("    " + a.julia_pre + "\n")
             f.write("    ierr = Ref{Cint}()\n    ")
-            f.write("api__result__ = " if (
+            f.write("api_result_ = " if (
                 (rtype is oint) or (rtype is odouble)) else "")
             c_name = c_mpath + name[0].upper() + name[1:]
             f.write("ccall((:" + c_name + ", " +
@@ -1467,11 +1480,10 @@ class API:
                     ("," if not len(args) else "") + "),\n" + " " * 10 +
                     ", ".join(tuple(a.julia_arg
                                     for a in args) + ("ierr", )) + ")\n")
-            f.write('    ierr[] != 0 && error("' + c_name +
-                    ' returned non-zero error code: $(ierr[])")\n')
+            f.write('    ierr[] != 0 && error(gmsh.logger.getLastError())\n')
             for a in args:
                 if a.julia_post: f.write("    " + a.julia_post + "\n")
-            r = (["api__result__"]) if rtype else []
+            r = (["api_result_"]) if rtype else []
             r += list((o.julia_return for o in oargs))
             f.write("    return ")
             if len(r) == 0:
diff --git a/api/gen.py b/api/gen.py
index db9fa3f988..953cd874a9 100644
--- a/api/gen.py
+++ b/api/gen.py
@@ -947,6 +947,9 @@ logger.add('getWallTime', doc, odouble)
 doc = '''Return CPU time.'''
 logger.add('getCpuTime', doc, odouble)
 
+doc = '''Return last error message, if any.'''
+logger.add('getLastError', doc, None, ostring('error'))
+
 ################################################################################
 
 api.write_cpp()
diff --git a/api/gmsh.h b/api/gmsh.h
index 121494025a..2db5e6c6a2 100644
--- a/api/gmsh.h
+++ b/api/gmsh.h
@@ -3013,6 +3013,11 @@ namespace gmsh { // Top-level functions
     // Return CPU time.
     GMSH_API double getCpuTime();
 
+    // gmsh::logger::getLastError
+    //
+    // Return last error message, if any.
+    GMSH_API void getLastError(std::string & error);
+
   } // namespace logger
 
 } // namespace gmsh
diff --git a/api/gmsh.h_cwrap b/api/gmsh.h_cwrap
index fca1de8b30..7545b4e03f 100644
--- a/api/gmsh.h_cwrap
+++ b/api/gmsh.h_cwrap
@@ -88,6 +88,17 @@ namespace gmsh {
     *sizeSize = v.size();
   }
   
+  inline void throwLastError()
+  {
+     int ierr = 0;
+     char *api_error_;
+     gmshLoggerGetLastError(&api_error_, &ierr);
+     if(ierr) throw "Could not get last error";
+     std::string error = std::string(api_error_);
+     gmshFree(api_error_);
+     throw error;
+  }
+
 }
 
 namespace gmsh { // Top-level functions
@@ -102,7 +113,7 @@ namespace gmsh { // Top-level functions
   {
     int ierr = 0;
     gmshInitialize(argc, argv, (int)readConfigFiles, &ierr);
-    if(ierr) throw ierr;
+    if(ierr) throwLastError();
   }
 
   // Finalize Gmsh. This must be called when you are done using the Gmsh API.
@@ -110,7 +121,7 @@ namespace gmsh { // Top-level functions
   {
     int ierr = 0;
     gmshFinalize(&ierr);
-    if(ierr) throw ierr;
+    if(ierr) throwLastError();
   }
 
   // Open a file. Equivalent to the `File->Open' menu in the Gmsh app. Handling of
@@ -120,7 +131,7 @@ namespace gmsh { // Top-level functions
   {
     int ierr = 0;
     gmshOpen(fileName.c_str(), &ierr);
-    if(ierr) throw ierr;
+    if(ierr) throwLastError();
   }
 
   // Merge a file. Equivalent to the `File->Merge' menu in the Gmsh app. Handling
@@ -130,7 +141,7 @@ namespace gmsh { // Top-level functions
   {
     int ierr = 0;
     gmshMerge(fileName.c_str(), &ierr);
-    if(ierr) throw ierr;
+    if(ierr) throwLastError();
   }
 
   // Write a file. The export format is determined by the file extension.
@@ -138,7 +149,7 @@ namespace gmsh { // Top-level functions
   {
     int ierr = 0;
     gmshWrite(fileName.c_str(), &ierr);
-    if(ierr) throw ierr;
+    if(ierr) throwLastError();
   }
 
   // Clear all loaded models and post-processing data, and add a new empty model.
@@ -146,7 +157,7 @@ namespace gmsh { // Top-level functions
   {
     int ierr = 0;
     gmshClear(&ierr);
-    if(ierr) throw ierr;
+    if(ierr) throwLastError();
   }
 
   namespace option { // Option handling functions
@@ -159,7 +170,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       gmshOptionSetNumber(name.c_str(), value, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
     }
 
     // Get the `value' of a numerical option. `name' is of the form
@@ -170,7 +181,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       gmshOptionGetNumber(name.c_str(), &value, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
     }
 
     // Set a string option to `value'. `name' is of the form "category.option" or
@@ -181,7 +192,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       gmshOptionSetString(name.c_str(), value.c_str(), &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
     }
 
     // Get the `value' of a string option. `name' is of the form "category.option"
@@ -193,7 +204,7 @@ namespace gmsh { // Top-level functions
       int ierr = 0;
       char *api_value_;
       gmshOptionGetString(name.c_str(), &api_value_, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       value = std::string(api_value_); gmshFree(api_value_);
     }
 
@@ -210,7 +221,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       gmshOptionSetColor(name.c_str(), r, g, b, a, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
     }
 
     // Get the `r', `g', `b', `a' value of a color option. `name' is of the form
@@ -225,7 +236,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       gmshOptionGetColor(name.c_str(), &r, &g, &b, &a, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
     }
 
   } // namespace option
@@ -237,7 +248,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       gmshModelAdd(name.c_str(), &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
     }
 
     // Remove the current model.
@@ -245,7 +256,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       gmshModelRemove(&ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
     }
 
     // List the names of all models.
@@ -254,7 +265,7 @@ namespace gmsh { // Top-level functions
       int ierr = 0;
       char **api_names_; size_t api_names_n_;
       gmshModelList(&api_names_, &api_names_n_, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       names.resize(api_names_n_); for(size_t i = 0; i < api_names_n_; ++i){ names[i] = std::string(api_names_[i]); gmshFree(api_names_[i]); } gmshFree(api_names_);
     }
 
@@ -264,7 +275,7 @@ namespace gmsh { // Top-level functions
       int ierr = 0;
       char *api_name_;
       gmshModelGetCurrent(&api_name_, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       name = std::string(api_name_); gmshFree(api_name_);
     }
 
@@ -274,7 +285,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       gmshModelSetCurrent(name.c_str(), &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
     }
 
     // Get all the entities in the current model. If `dim' is >= 0, return only the
@@ -286,7 +297,7 @@ namespace gmsh { // Top-level functions
       int ierr = 0;
       int *api_dimTags_; size_t api_dimTags_n_;
       gmshModelGetEntities(&api_dimTags_, &api_dimTags_n_, dim, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       dimTags.resize(api_dimTags_n_ / 2); for(size_t i = 0; i < api_dimTags_n_ / 2; ++i){ dimTags[i].first = api_dimTags_[i * 2 + 0]; dimTags[i].second = api_dimTags_[i * 2 + 1]; } gmshFree(api_dimTags_);
     }
 
@@ -297,7 +308,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       gmshModelSetEntityName(dim, tag, name.c_str(), &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
     }
 
     // Get the name of the entity of dimension `dim' and tag `tag'.
@@ -308,7 +319,7 @@ namespace gmsh { // Top-level functions
       int ierr = 0;
       char *api_name_;
       gmshModelGetEntityName(dim, tag, &api_name_, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       name = std::string(api_name_); gmshFree(api_name_);
     }
 
@@ -321,7 +332,7 @@ namespace gmsh { // Top-level functions
       int ierr = 0;
       int *api_dimTags_; size_t api_dimTags_n_;
       gmshModelGetPhysicalGroups(&api_dimTags_, &api_dimTags_n_, dim, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       dimTags.resize(api_dimTags_n_ / 2); for(size_t i = 0; i < api_dimTags_n_ / 2; ++i){ dimTags[i].first = api_dimTags_[i * 2 + 0]; dimTags[i].second = api_dimTags_[i * 2 + 1]; } gmshFree(api_dimTags_);
     }
 
@@ -334,7 +345,7 @@ namespace gmsh { // Top-level functions
       int ierr = 0;
       int *api_tags_; size_t api_tags_n_;
       gmshModelGetEntitiesForPhysicalGroup(dim, tag, &api_tags_, &api_tags_n_, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       tags.assign(api_tags_, api_tags_ + api_tags_n_); gmshFree(api_tags_);
     }
 
@@ -347,7 +358,7 @@ namespace gmsh { // Top-level functions
       int ierr = 0;
       int *api_physicalTags_; size_t api_physicalTags_n_;
       gmshModelGetPhysicalGroupsForEntity(dim, tag, &api_physicalTags_, &api_physicalTags_n_, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       physicalTags.assign(api_physicalTags_, api_physicalTags_ + api_physicalTags_n_); gmshFree(api_physicalTags_);
     }
 
@@ -361,7 +372,7 @@ namespace gmsh { // Top-level functions
       int ierr = 0;
       int *api_tags_; size_t api_tags_n_; vector2ptr(tags, &api_tags_, &api_tags_n_);
       int result_api_ = gmshModelAddPhysicalGroup(dim, api_tags_, api_tags_n_, tag, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       gmshFree(api_tags_);
       return result_api_;
     }
@@ -373,7 +384,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       gmshModelSetPhysicalName(dim, tag, name.c_str(), &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
     }
 
     // Get the name of the physical group of dimension `dim' and tag `tag'.
@@ -384,7 +395,7 @@ namespace gmsh { // Top-level functions
       int ierr = 0;
       char *api_name_;
       gmshModelGetPhysicalName(dim, tag, &api_name_, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       name = std::string(api_name_); gmshFree(api_name_);
     }
 
@@ -404,7 +415,7 @@ namespace gmsh { // Top-level functions
       int *api_dimTags_; size_t api_dimTags_n_; vectorpair2intptr(dimTags, &api_dimTags_, &api_dimTags_n_);
       int *api_outDimTags_; size_t api_outDimTags_n_;
       gmshModelGetBoundary(api_dimTags_, api_dimTags_n_, &api_outDimTags_, &api_outDimTags_n_, (int)combined, (int)oriented, (int)recursive, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       gmshFree(api_dimTags_);
       outDimTags.resize(api_outDimTags_n_ / 2); for(size_t i = 0; i < api_outDimTags_n_ / 2; ++i){ outDimTags[i].first = api_outDimTags_[i * 2 + 0]; outDimTags[i].second = api_outDimTags_[i * 2 + 1]; } gmshFree(api_outDimTags_);
     }
@@ -425,7 +436,7 @@ namespace gmsh { // Top-level functions
       int ierr = 0;
       int *api_tags_; size_t api_tags_n_;
       gmshModelGetEntitiesInBoundingBox(xmin, ymin, zmin, xmax, ymax, zmax, &api_tags_, &api_tags_n_, dim, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       tags.resize(api_tags_n_ / 2); for(size_t i = 0; i < api_tags_n_ / 2; ++i){ tags[i].first = api_tags_[i * 2 + 0]; tags[i].second = api_tags_[i * 2 + 1]; } gmshFree(api_tags_);
     }
 
@@ -443,7 +454,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       gmshModelGetBoundingBox(dim, tag, &xmin, &ymin, &zmin, &xmax, &ymax, &zmax, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
     }
 
     // Get the geometrical dimension of the current model.
@@ -451,7 +462,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       int result_api_ = gmshModelGetDimension(&ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       return result_api_;
     }
 
@@ -467,7 +478,7 @@ namespace gmsh { // Top-level functions
       int ierr = 0;
       int *api_boundary_; size_t api_boundary_n_; vector2ptr(boundary, &api_boundary_, &api_boundary_n_);
       int result_api_ = gmshModelAddDiscreteEntity(dim, tag, api_boundary_, api_boundary_n_, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       gmshFree(api_boundary_);
       return result_api_;
     }
@@ -480,7 +491,7 @@ namespace gmsh { // Top-level functions
       int ierr = 0;
       int *api_dimTags_; size_t api_dimTags_n_; vectorpair2intptr(dimTags, &api_dimTags_, &api_dimTags_n_);
       gmshModelRemoveEntities(api_dimTags_, api_dimTags_n_, (int)recursive, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       gmshFree(api_dimTags_);
     }
 
@@ -489,7 +500,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       gmshModelRemoveEntityName(name.c_str(), &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
     }
 
     // Remove the physical groups `dimTags' of the current model. If `dimTags' is
@@ -499,7 +510,7 @@ namespace gmsh { // Top-level functions
       int ierr = 0;
       int *api_dimTags_; size_t api_dimTags_n_; vectorpair2intptr(dimTags, &api_dimTags_, &api_dimTags_n_);
       gmshModelRemovePhysicalGroups(api_dimTags_, api_dimTags_n_, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       gmshFree(api_dimTags_);
     }
 
@@ -508,7 +519,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       gmshModelRemovePhysicalName(name.c_str(), &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
     }
 
     // Get the type of the entity of dimension `dim' and tag `tag'.
@@ -519,7 +530,7 @@ namespace gmsh { // Top-level functions
       int ierr = 0;
       char *api_entityType_;
       gmshModelGetType(dim, tag, &api_entityType_, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       entityType = std::string(api_entityType_); gmshFree(api_entityType_);
     }
 
@@ -533,7 +544,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       gmshModelGetParent(dim, tag, &parentDim, &parentTag, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
     }
 
     // In a partitioned model, return the tags of the partition(s) to which the
@@ -545,7 +556,7 @@ namespace gmsh { // Top-level functions
       int ierr = 0;
       int *api_partitions_; size_t api_partitions_n_;
       gmshModelGetPartitions(dim, tag, &api_partitions_, &api_partitions_n_, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       partitions.assign(api_partitions_, api_partitions_ + api_partitions_n_); gmshFree(api_partitions_);
     }
 
@@ -565,7 +576,7 @@ namespace gmsh { // Top-level functions
       double *api_parametricCoord_; size_t api_parametricCoord_n_; vector2ptr(parametricCoord, &api_parametricCoord_, &api_parametricCoord_n_);
       double *api_coord_; size_t api_coord_n_;
       gmshModelGetValue(dim, tag, api_parametricCoord_, api_parametricCoord_n_, &api_coord_, &api_coord_n_, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       gmshFree(api_parametricCoord_);
       coord.assign(api_coord_, api_coord_ + api_coord_n_); gmshFree(api_coord_);
     }
@@ -588,7 +599,7 @@ namespace gmsh { // Top-level functions
       double *api_parametricCoord_; size_t api_parametricCoord_n_; vector2ptr(parametricCoord, &api_parametricCoord_, &api_parametricCoord_n_);
       double *api_derivatives_; size_t api_derivatives_n_;
       gmshModelGetDerivative(dim, tag, api_parametricCoord_, api_parametricCoord_n_, &api_derivatives_, &api_derivatives_n_, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       gmshFree(api_parametricCoord_);
       derivatives.assign(api_derivatives_, api_derivatives_ + api_derivatives_n_); gmshFree(api_derivatives_);
     }
@@ -607,7 +618,7 @@ namespace gmsh { // Top-level functions
       double *api_parametricCoord_; size_t api_parametricCoord_n_; vector2ptr(parametricCoord, &api_parametricCoord_, &api_parametricCoord_n_);
       double *api_curvatures_; size_t api_curvatures_n_;
       gmshModelGetCurvature(dim, tag, api_parametricCoord_, api_parametricCoord_n_, &api_curvatures_, &api_curvatures_n_, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       gmshFree(api_parametricCoord_);
       curvatures.assign(api_curvatures_, api_curvatures_ + api_curvatures_n_); gmshFree(api_curvatures_);
     }
@@ -630,7 +641,7 @@ namespace gmsh { // Top-level functions
       double *api_directionMax_; size_t api_directionMax_n_;
       double *api_directionMin_; size_t api_directionMin_n_;
       gmshModelGetPrincipalCurvatures(tag, api_parametricCoord_, api_parametricCoord_n_, &api_curvatureMax_, &api_curvatureMax_n_, &api_curvatureMin_, &api_curvatureMin_n_, &api_directionMax_, &api_directionMax_n_, &api_directionMin_, &api_directionMin_n_, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       gmshFree(api_parametricCoord_);
       curvatureMax.assign(api_curvatureMax_, api_curvatureMax_ + api_curvatureMax_n_); gmshFree(api_curvatureMax_);
       curvatureMin.assign(api_curvatureMin_, api_curvatureMin_ + api_curvatureMin_n_); gmshFree(api_curvatureMin_);
@@ -650,7 +661,7 @@ namespace gmsh { // Top-level functions
       double *api_parametricCoord_; size_t api_parametricCoord_n_; vector2ptr(parametricCoord, &api_parametricCoord_, &api_parametricCoord_n_);
       double *api_normals_; size_t api_normals_n_;
       gmshModelGetNormal(tag, api_parametricCoord_, api_parametricCoord_n_, &api_normals_, &api_normals_n_, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       gmshFree(api_parametricCoord_);
       normals.assign(api_normals_, api_normals_ + api_normals_n_); gmshFree(api_normals_);
     }
@@ -670,7 +681,7 @@ namespace gmsh { // Top-level functions
       double *api_coord_; size_t api_coord_n_; vector2ptr(coord, &api_coord_, &api_coord_n_);
       double *api_parametricCoord_; size_t api_parametricCoord_n_;
       gmshModelGetParametrization(dim, tag, api_coord_, api_coord_n_, &api_parametricCoord_, &api_parametricCoord_n_, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       gmshFree(api_coord_);
       parametricCoord.assign(api_parametricCoord_, api_parametricCoord_ + api_parametricCoord_n_); gmshFree(api_parametricCoord_);
     }
@@ -686,7 +697,7 @@ namespace gmsh { // Top-level functions
       double *api_min_; size_t api_min_n_;
       double *api_max_; size_t api_max_n_;
       gmshModelGetParametrizationBounds(dim, tag, &api_min_, &api_min_n_, &api_max_, &api_max_n_, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       min.assign(api_min_, api_min_ + api_min_n_); gmshFree(api_min_);
       max.assign(api_max_, api_max_ + api_max_n_); gmshFree(api_max_);
     }
@@ -702,7 +713,7 @@ namespace gmsh { // Top-level functions
       int ierr = 0;
       double *api_parametricCoord_; size_t api_parametricCoord_n_; vector2ptr(parametricCoord, &api_parametricCoord_, &api_parametricCoord_n_);
       int result_api_ = gmshModelIsInside(dim, tag, api_parametricCoord_, api_parametricCoord_n_, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       gmshFree(api_parametricCoord_);
       return result_api_;
     }
@@ -724,7 +735,7 @@ namespace gmsh { // Top-level functions
       double *api_closestCoord_; size_t api_closestCoord_n_;
       double *api_parametricCoord_; size_t api_parametricCoord_n_;
       gmshModelGetClosestPoint(dim, tag, api_coord_, api_coord_n_, &api_closestCoord_, &api_closestCoord_n_, &api_parametricCoord_, &api_parametricCoord_n_, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       gmshFree(api_coord_);
       closestCoord.assign(api_closestCoord_, api_closestCoord_ + api_closestCoord_n_); gmshFree(api_closestCoord_);
       parametricCoord.assign(api_parametricCoord_, api_parametricCoord_ + api_parametricCoord_n_); gmshFree(api_parametricCoord_);
@@ -747,7 +758,7 @@ namespace gmsh { // Top-level functions
       double *api_parametricCoord_; size_t api_parametricCoord_n_; vector2ptr(parametricCoord, &api_parametricCoord_, &api_parametricCoord_n_);
       double *api_surfaceParametricCoord_; size_t api_surfaceParametricCoord_n_;
       gmshModelReparametrizeOnSurface(dim, tag, api_parametricCoord_, api_parametricCoord_n_, surfaceTag, &api_surfaceParametricCoord_, &api_surfaceParametricCoord_n_, which, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       gmshFree(api_parametricCoord_);
       surfaceParametricCoord.assign(api_surfaceParametricCoord_, api_surfaceParametricCoord_ + api_surfaceParametricCoord_n_); gmshFree(api_surfaceParametricCoord_);
     }
@@ -761,7 +772,7 @@ namespace gmsh { // Top-level functions
       int ierr = 0;
       int *api_dimTags_; size_t api_dimTags_n_; vectorpair2intptr(dimTags, &api_dimTags_, &api_dimTags_n_);
       gmshModelSetVisibility(api_dimTags_, api_dimTags_n_, value, (int)recursive, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       gmshFree(api_dimTags_);
     }
 
@@ -772,7 +783,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       gmshModelGetVisibility(dim, tag, &value, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
     }
 
     // Set the color of the model entities `dimTags' to the RGBA value (`r', `g',
@@ -788,7 +799,7 @@ namespace gmsh { // Top-level functions
       int ierr = 0;
       int *api_dimTags_; size_t api_dimTags_n_; vectorpair2intptr(dimTags, &api_dimTags_, &api_dimTags_n_);
       gmshModelSetColor(api_dimTags_, api_dimTags_n_, r, g, b, a, (int)recursive, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       gmshFree(api_dimTags_);
     }
 
@@ -802,7 +813,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       gmshModelGetColor(dim, tag, &r, &g, &b, &a, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
     }
 
     // Set the `x', `y', `z' coordinates of a geometrical point.
@@ -813,7 +824,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       gmshModelSetCoordinates(tag, x, y, z, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
     }
 
     namespace mesh { // Mesh functions
@@ -824,7 +835,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         gmshModelMeshGenerate(dim, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
       }
 
       // Partition the mesh of the current model into `numPart' partitions.
@@ -832,7 +843,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         gmshModelMeshPartition(numPart, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
       }
 
       // Unpartition the mesh of the current model.
@@ -840,7 +851,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         gmshModelMeshUnpartition(&ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
       }
 
       // Optimize the mesh of the current model using `method' (empty for default
@@ -859,7 +870,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_dimTags_; size_t api_dimTags_n_; vectorpair2intptr(dimTags, &api_dimTags_, &api_dimTags_n_);
         gmshModelMeshOptimize(method.c_str(), (int)force, niter, api_dimTags_, api_dimTags_n_, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_dimTags_);
       }
 
@@ -868,7 +879,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         gmshModelMeshRecombine(&ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
       }
 
       // Refine the mesh of the current model by uniformly splitting the elements.
@@ -876,7 +887,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         gmshModelMeshRefine(&ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
       }
 
       // Set the order of the elements in the mesh of the current model to `order'.
@@ -884,7 +895,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         gmshModelMeshSetOrder(order, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
       }
 
       // Get the last entities (if any) where a meshing error occurred. Currently
@@ -894,7 +905,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_dimTags_; size_t api_dimTags_n_;
         gmshModelMeshGetLastEntityError(&api_dimTags_, &api_dimTags_n_, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         dimTags.resize(api_dimTags_n_ / 2); for(size_t i = 0; i < api_dimTags_n_ / 2; ++i){ dimTags[i].first = api_dimTags_[i * 2 + 0]; dimTags[i].second = api_dimTags_[i * 2 + 1]; } gmshFree(api_dimTags_);
       }
 
@@ -905,7 +916,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         size_t *api_nodeTags_; size_t api_nodeTags_n_;
         gmshModelMeshGetLastNodeError(&api_nodeTags_, &api_nodeTags_n_, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         nodeTags.assign(api_nodeTags_, api_nodeTags_ + api_nodeTags_n_); gmshFree(api_nodeTags_);
       }
 
@@ -918,7 +929,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_dimTags_; size_t api_dimTags_n_; vectorpair2intptr(dimTags, &api_dimTags_, &api_dimTags_n_);
         gmshModelMeshClear(api_dimTags_, api_dimTags_n_, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_dimTags_);
       }
 
@@ -948,7 +959,7 @@ namespace gmsh { // Top-level functions
         double *api_coord_; size_t api_coord_n_;
         double *api_parametricCoord_; size_t api_parametricCoord_n_;
         gmshModelMeshGetNodes(&api_nodeTags_, &api_nodeTags_n_, &api_coord_, &api_coord_n_, &api_parametricCoord_, &api_parametricCoord_n_, dim, tag, (int)includeBoundary, (int)returnParametricCoord, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         nodeTags.assign(api_nodeTags_, api_nodeTags_ + api_nodeTags_n_); gmshFree(api_nodeTags_);
         coord.assign(api_coord_, api_coord_ + api_coord_n_); gmshFree(api_coord_);
         parametricCoord.assign(api_parametricCoord_, api_parametricCoord_ + api_parametricCoord_n_); gmshFree(api_parametricCoord_);
@@ -968,7 +979,7 @@ namespace gmsh { // Top-level functions
         double *api_coord_; size_t api_coord_n_;
         double *api_parametricCoord_; size_t api_parametricCoord_n_;
         gmshModelMeshGetNodesByElementType(elementType, &api_nodeTags_, &api_nodeTags_n_, &api_coord_, &api_coord_n_, &api_parametricCoord_, &api_parametricCoord_n_, tag, (int)returnParametricCoord, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         nodeTags.assign(api_nodeTags_, api_nodeTags_ + api_nodeTags_n_); gmshFree(api_nodeTags_);
         coord.assign(api_coord_, api_coord_ + api_coord_n_); gmshFree(api_coord_);
         parametricCoord.assign(api_parametricCoord_, api_parametricCoord_ + api_parametricCoord_n_); gmshFree(api_parametricCoord_);
@@ -986,7 +997,7 @@ namespace gmsh { // Top-level functions
         double *api_coord_; size_t api_coord_n_;
         double *api_parametricCoord_; size_t api_parametricCoord_n_;
         gmshModelMeshGetNode(nodeTag, &api_coord_, &api_coord_n_, &api_parametricCoord_, &api_parametricCoord_n_, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         coord.assign(api_coord_, api_coord_ + api_coord_n_); gmshFree(api_coord_);
         parametricCoord.assign(api_parametricCoord_, api_parametricCoord_ + api_parametricCoord_n_); gmshFree(api_parametricCoord_);
       }
@@ -1003,7 +1014,7 @@ namespace gmsh { // Top-level functions
         double *api_coord_; size_t api_coord_n_; vector2ptr(coord, &api_coord_, &api_coord_n_);
         double *api_parametricCoord_; size_t api_parametricCoord_n_; vector2ptr(parametricCoord, &api_parametricCoord_, &api_parametricCoord_n_);
         gmshModelMeshSetNode(nodeTag, api_coord_, api_coord_n_, api_parametricCoord_, api_parametricCoord_n_, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_coord_);
         gmshFree(api_parametricCoord_);
       }
@@ -1013,7 +1024,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         gmshModelMeshRebuildNodeCache((int)onlyIfNecessary, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
       }
 
       // Rebuild the element cache.
@@ -1021,7 +1032,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         gmshModelMeshRebuildElementCache((int)onlyIfNecessary, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
       }
 
       // Get the nodes from all the elements belonging to the physical group of
@@ -1037,7 +1048,7 @@ namespace gmsh { // Top-level functions
         size_t *api_nodeTags_; size_t api_nodeTags_n_;
         double *api_coord_; size_t api_coord_n_;
         gmshModelMeshGetNodesForPhysicalGroup(dim, tag, &api_nodeTags_, &api_nodeTags_n_, &api_coord_, &api_coord_n_, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         nodeTags.assign(api_nodeTags_, api_nodeTags_ + api_nodeTags_n_); gmshFree(api_nodeTags_);
         coord.assign(api_coord_, api_coord_ + api_coord_n_); gmshFree(api_coord_);
       }
@@ -1062,7 +1073,7 @@ namespace gmsh { // Top-level functions
         double *api_coord_; size_t api_coord_n_; vector2ptr(coord, &api_coord_, &api_coord_n_);
         double *api_parametricCoord_; size_t api_parametricCoord_n_; vector2ptr(parametricCoord, &api_parametricCoord_, &api_parametricCoord_n_);
         gmshModelMeshAddNodes(dim, tag, api_nodeTags_, api_nodeTags_n_, api_coord_, api_coord_n_, api_parametricCoord_, api_parametricCoord_n_, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_nodeTags_);
         gmshFree(api_coord_);
         gmshFree(api_parametricCoord_);
@@ -1076,7 +1087,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         gmshModelMeshReclassifyNodes(&ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
       }
 
       // Relocate the nodes classified on the entity of dimension `dim' and tag
@@ -1088,7 +1099,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         gmshModelMeshRelocateNodes(dim, tag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
       }
 
       // Get the elements classified on the entity of dimension `dim' and tag
@@ -1115,7 +1126,7 @@ namespace gmsh { // Top-level functions
         size_t **api_elementTags_; size_t *api_elementTags_n_, api_elementTags_nn_;
         size_t **api_nodeTags_; size_t *api_nodeTags_n_, api_nodeTags_nn_;
         gmshModelMeshGetElements(&api_elementTypes_, &api_elementTypes_n_, &api_elementTags_, &api_elementTags_n_, &api_elementTags_nn_, &api_nodeTags_, &api_nodeTags_n_, &api_nodeTags_nn_, dim, tag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         elementTypes.assign(api_elementTypes_, api_elementTypes_ + api_elementTypes_n_); gmshFree(api_elementTypes_);
         elementTags.resize(api_elementTags_nn_); for(size_t i = 0; i < api_elementTags_nn_; ++i){ elementTags[i].assign(api_elementTags_[i], api_elementTags_[i] + api_elementTags_n_[i]); gmshFree(api_elementTags_[i]); } gmshFree(api_elementTags_); gmshFree(api_elementTags_n_);
         nodeTags.resize(api_nodeTags_nn_); for(size_t i = 0; i < api_nodeTags_nn_; ++i){ nodeTags[i].assign(api_nodeTags_[i], api_nodeTags_[i] + api_nodeTags_n_[i]); gmshFree(api_nodeTags_[i]); } gmshFree(api_nodeTags_); gmshFree(api_nodeTags_n_);
@@ -1132,7 +1143,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         size_t *api_nodeTags_; size_t api_nodeTags_n_;
         gmshModelMeshGetElement(elementTag, &elementType, &api_nodeTags_, &api_nodeTags_n_, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         nodeTags.assign(api_nodeTags_, api_nodeTags_ + api_nodeTags_n_); gmshFree(api_nodeTags_);
       }
 
@@ -1158,7 +1169,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         size_t *api_nodeTags_; size_t api_nodeTags_n_;
         gmshModelMeshGetElementByCoordinates(x, y, z, &elementTag, &elementType, &api_nodeTags_, &api_nodeTags_n_, &u, &v, &w, dim, (int)strict, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         nodeTags.assign(api_nodeTags_, api_nodeTags_ + api_nodeTags_n_); gmshFree(api_nodeTags_);
       }
 
@@ -1179,7 +1190,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         size_t *api_elementTags_; size_t api_elementTags_n_;
         gmshModelMeshGetElementsByCoordinates(x, y, z, &api_elementTags_, &api_elementTags_n_, dim, (int)strict, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         elementTags.assign(api_elementTags_, api_elementTags_ + api_elementTags_n_); gmshFree(api_elementTags_);
       }
 
@@ -1198,7 +1209,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         gmshModelMeshGetLocalCoordinatesInElement(elementTag, x, y, z, &u, &v, &w, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
       }
 
       // Get the types of elements in the entity of dimension `dim' and tag `tag'.
@@ -1211,7 +1222,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_elementTypes_; size_t api_elementTypes_n_;
         gmshModelMeshGetElementTypes(&api_elementTypes_, &api_elementTypes_n_, dim, tag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         elementTypes.assign(api_elementTypes_, api_elementTypes_ + api_elementTypes_n_); gmshFree(api_elementTypes_);
       }
 
@@ -1225,7 +1236,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         int result_api_ = gmshModelMeshGetElementType(familyName.c_str(), order, (int)serendip, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         return result_api_;
       }
 
@@ -1246,7 +1257,7 @@ namespace gmsh { // Top-level functions
         char *api_elementName_;
         double *api_localNodeCoord_; size_t api_localNodeCoord_n_;
         gmshModelMeshGetElementProperties(elementType, &api_elementName_, &dim, &order, &numNodes, &api_localNodeCoord_, &api_localNodeCoord_n_, &numPrimaryNodes, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         elementName = std::string(api_elementName_); gmshFree(api_elementName_);
         localNodeCoord.assign(api_localNodeCoord_, api_localNodeCoord_ + api_localNodeCoord_n_); gmshFree(api_localNodeCoord_);
       }
@@ -1271,7 +1282,7 @@ namespace gmsh { // Top-level functions
         size_t *api_elementTags_; size_t api_elementTags_n_;
         size_t *api_nodeTags_; size_t api_nodeTags_n_;
         gmshModelMeshGetElementsByType(elementType, &api_elementTags_, &api_elementTags_n_, &api_nodeTags_, &api_nodeTags_n_, tag, task, numTasks, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         elementTags.assign(api_elementTags_, api_elementTags_ + api_elementTags_n_); gmshFree(api_elementTags_);
         nodeTags.assign(api_nodeTags_, api_nodeTags_ + api_nodeTags_n_); gmshFree(api_nodeTags_);
       }
@@ -1289,7 +1300,7 @@ namespace gmsh { // Top-level functions
         size_t *api_elementTags_; size_t api_elementTags_n_;
         size_t *api_nodeTags_; size_t api_nodeTags_n_;
         gmshModelMeshPreallocateElementsByType(elementType, (int)elementTag, (int)nodeTag, &api_elementTags_, &api_elementTags_n_, &api_nodeTags_, &api_nodeTags_n_, tag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         elementTags.assign(api_elementTags_, api_elementTags_ + api_elementTags_n_); gmshFree(api_elementTags_);
         nodeTags.assign(api_nodeTags_, api_nodeTags_ + api_nodeTags_n_); gmshFree(api_nodeTags_);
       }
@@ -1315,7 +1326,7 @@ namespace gmsh { // Top-level functions
         size_t **api_elementTags_; size_t *api_elementTags_n_, api_elementTags_nn_; vectorvector2ptrptr(elementTags, &api_elementTags_, &api_elementTags_n_, &api_elementTags_nn_);
         size_t **api_nodeTags_; size_t *api_nodeTags_n_, api_nodeTags_nn_; vectorvector2ptrptr(nodeTags, &api_nodeTags_, &api_nodeTags_n_, &api_nodeTags_nn_);
         gmshModelMeshAddElements(dim, tag, api_elementTypes_, api_elementTypes_n_, (const size_t **)api_elementTags_, api_elementTags_n_, api_elementTags_nn_, (const size_t **)api_nodeTags_, api_nodeTags_n_, api_nodeTags_nn_, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_elementTypes_);
         for(size_t i = 0; i < api_elementTags_nn_; ++i){ gmshFree(api_elementTags_[i]); } gmshFree(api_elementTags_); gmshFree(api_elementTags_n_);
         for(size_t i = 0; i < api_nodeTags_nn_; ++i){ gmshFree(api_nodeTags_[i]); } gmshFree(api_nodeTags_); gmshFree(api_nodeTags_n_);
@@ -1337,7 +1348,7 @@ namespace gmsh { // Top-level functions
         size_t *api_elementTags_; size_t api_elementTags_n_; vector2ptr(elementTags, &api_elementTags_, &api_elementTags_n_);
         size_t *api_nodeTags_; size_t api_nodeTags_n_; vector2ptr(nodeTags, &api_nodeTags_, &api_nodeTags_n_);
         gmshModelMeshAddElementsByType(tag, elementType, api_elementTags_, api_elementTags_n_, api_nodeTags_, api_nodeTags_n_, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_elementTags_);
         gmshFree(api_nodeTags_);
       }
@@ -1357,7 +1368,7 @@ namespace gmsh { // Top-level functions
         double *api_localCoord_; size_t api_localCoord_n_;
         double *api_weights_; size_t api_weights_n_;
         gmshModelMeshGetIntegrationPoints(elementType, integrationType.c_str(), &api_localCoord_, &api_localCoord_n_, &api_weights_, &api_weights_n_, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         localCoord.assign(api_localCoord_, api_localCoord_ + api_localCoord_n_); gmshFree(api_localCoord_);
         weights.assign(api_weights_, api_weights_ + api_weights_n_); gmshFree(api_weights_);
       }
@@ -1391,7 +1402,7 @@ namespace gmsh { // Top-level functions
         double *api_determinants_; size_t api_determinants_n_;
         double *api_coord_; size_t api_coord_n_;
         gmshModelMeshGetJacobians(elementType, api_localCoord_, api_localCoord_n_, &api_jacobians_, &api_jacobians_n_, &api_determinants_, &api_determinants_n_, &api_coord_, &api_coord_n_, tag, task, numTasks, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_localCoord_);
         jacobians.assign(api_jacobians_, api_jacobians_ + api_jacobians_n_); gmshFree(api_jacobians_);
         determinants.assign(api_determinants_, api_determinants_ + api_determinants_n_); gmshFree(api_determinants_);
@@ -1415,7 +1426,7 @@ namespace gmsh { // Top-level functions
         double *api_determinants_; size_t api_determinants_n_;
         double *api_coord_; size_t api_coord_n_;
         gmshModelMeshPreallocateJacobians(elementType, numEvaluationPoints, (int)allocateJacobians, (int)allocateDeterminants, (int)allocateCoord, &api_jacobians_, &api_jacobians_n_, &api_determinants_, &api_determinants_n_, &api_coord_, &api_coord_n_, tag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         jacobians.assign(api_jacobians_, api_jacobians_ + api_jacobians_n_); gmshFree(api_jacobians_);
         determinants.assign(api_determinants_, api_determinants_ + api_determinants_n_); gmshFree(api_determinants_);
         coord.assign(api_coord_, api_coord_ + api_coord_n_); gmshFree(api_coord_);
@@ -1444,7 +1455,7 @@ namespace gmsh { // Top-level functions
         double *api_determinants_; size_t api_determinants_n_;
         double *api_coord_; size_t api_coord_n_;
         gmshModelMeshGetJacobian(elementTag, api_localCoord_, api_localCoord_n_, &api_jacobians_, &api_jacobians_n_, &api_determinants_, &api_determinants_n_, &api_coord_, &api_coord_n_, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_localCoord_);
         jacobians.assign(api_jacobians_, api_jacobians_ + api_jacobians_n_); gmshFree(api_jacobians_);
         determinants.assign(api_determinants_, api_determinants_ + api_determinants_n_); gmshFree(api_determinants_);
@@ -1480,7 +1491,7 @@ namespace gmsh { // Top-level functions
         double *api_basisFunctions_; size_t api_basisFunctions_n_;
         int *api_wantedOrientations_; size_t api_wantedOrientations_n_; vector2ptr(wantedOrientations, &api_wantedOrientations_, &api_wantedOrientations_n_);
         gmshModelMeshGetBasisFunctions(elementType, api_localCoord_, api_localCoord_n_, functionSpaceType.c_str(), &numComponents, &api_basisFunctions_, &api_basisFunctions_n_, &numOrientations, api_wantedOrientations_, api_wantedOrientations_n_, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_localCoord_);
         basisFunctions.assign(api_basisFunctions_, api_basisFunctions_ + api_basisFunctions_n_); gmshFree(api_basisFunctions_);
         gmshFree(api_wantedOrientations_);
@@ -1502,7 +1513,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_basisFunctionsOrientation_; size_t api_basisFunctionsOrientation_n_;
         gmshModelMeshGetBasisFunctionsOrientationForElements(elementType, functionSpaceType.c_str(), &api_basisFunctionsOrientation_, &api_basisFunctionsOrientation_n_, tag, task, numTasks, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         basisFunctionsOrientation.assign(api_basisFunctionsOrientation_, api_basisFunctionsOrientation_ + api_basisFunctionsOrientation_n_); gmshFree(api_basisFunctionsOrientation_);
       }
 
@@ -1513,7 +1524,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         gmshModelMeshGetBasisFunctionsOrientationForElement(elementTag, functionSpaceType.c_str(), &basisFunctionsOrientation, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
       }
 
       // Get the number of possible orientations for elements of type `elementType'
@@ -1523,7 +1534,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         int result_api_ = gmshModelMeshGetNumberOfOrientations(elementType, functionSpaceType.c_str(), &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         return result_api_;
       }
 
@@ -1536,7 +1547,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_basisFunctionsOrientation_; size_t api_basisFunctionsOrientation_n_;
         gmshModelMeshPreallocateBasisFunctionsOrientationForElements(elementType, &api_basisFunctionsOrientation_, &api_basisFunctionsOrientation_n_, tag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         basisFunctionsOrientation.assign(api_basisFunctionsOrientation_, api_basisFunctionsOrientation_ + api_basisFunctionsOrientation_n_); gmshFree(api_basisFunctionsOrientation_);
       }
 
@@ -1550,7 +1561,7 @@ namespace gmsh { // Top-level functions
         int *api_edgeNodes_; size_t api_edgeNodes_n_; vector2ptr(edgeNodes, &api_edgeNodes_, &api_edgeNodes_n_);
         int *api_edgeNum_; size_t api_edgeNum_n_;
         gmshModelMeshGetEdgeNumber(api_edgeNodes_, api_edgeNodes_n_, &api_edgeNum_, &api_edgeNum_n_, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_edgeNodes_);
         edgeNum.assign(api_edgeNum_, api_edgeNum_ + api_edgeNum_n_); gmshFree(api_edgeNum_);
       }
@@ -1565,7 +1576,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_localMultipliers_; size_t api_localMultipliers_n_;
         gmshModelMeshGetLocalMultipliersForHcurl0(elementType, &api_localMultipliers_, &api_localMultipliers_n_, tag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         localMultipliers.assign(api_localMultipliers_, api_localMultipliers_ + api_localMultipliers_n_); gmshFree(api_localMultipliers_);
       }
 
@@ -1586,7 +1597,7 @@ namespace gmsh { // Top-level functions
         int *api_keys_; size_t api_keys_n_;
         double *api_coord_; size_t api_coord_n_;
         gmshModelMeshGetKeysForElements(elementType, functionSpaceType.c_str(), &api_keys_, &api_keys_n_, &api_coord_, &api_coord_n_, tag, (int)returnCoord, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         keys.resize(api_keys_n_ / 2); for(size_t i = 0; i < api_keys_n_ / 2; ++i){ keys[i].first = api_keys_[i * 2 + 0]; keys[i].second = api_keys_[i * 2 + 1]; } gmshFree(api_keys_);
         coord.assign(api_coord_, api_coord_ + api_coord_n_); gmshFree(api_coord_);
       }
@@ -1602,7 +1613,7 @@ namespace gmsh { // Top-level functions
         int *api_keys_; size_t api_keys_n_;
         double *api_coord_; size_t api_coord_n_;
         gmshModelMeshGetKeysForElement(elementTag, functionSpaceType.c_str(), &api_keys_, &api_keys_n_, &api_coord_, &api_coord_n_, (int)returnCoord, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         keys.resize(api_keys_n_ / 2); for(size_t i = 0; i < api_keys_n_ / 2; ++i){ keys[i].first = api_keys_[i * 2 + 0]; keys[i].second = api_keys_[i * 2 + 1]; } gmshFree(api_keys_);
         coord.assign(api_coord_, api_coord_ + api_coord_n_); gmshFree(api_coord_);
       }
@@ -1614,7 +1625,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         int result_api_ = gmshModelMeshGetNumberOfKeysForElements(elementType, functionSpaceType.c_str(), &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         return result_api_;
       }
 
@@ -1633,7 +1644,7 @@ namespace gmsh { // Top-level functions
         int *api_keys_; size_t api_keys_n_; vectorpair2intptr(keys, &api_keys_, &api_keys_n_);
         int *api_infoKeys_; size_t api_infoKeys_n_;
         gmshModelMeshGetInformationForElements(api_keys_, api_keys_n_, elementType, functionSpaceType.c_str(), &api_infoKeys_, &api_infoKeys_n_, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_keys_);
         infoKeys.resize(api_infoKeys_n_ / 2); for(size_t i = 0; i < api_infoKeys_n_ / 2; ++i){ infoKeys[i].first = api_infoKeys_[i * 2 + 0]; infoKeys[i].second = api_infoKeys_[i * 2 + 1]; } gmshFree(api_infoKeys_);
       }
@@ -1656,7 +1667,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         double *api_barycenters_; size_t api_barycenters_n_;
         gmshModelMeshGetBarycenters(elementType, tag, (int)fast, (int)primary, &api_barycenters_, &api_barycenters_n_, task, numTasks, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         barycenters.assign(api_barycenters_, api_barycenters_ + api_barycenters_n_); gmshFree(api_barycenters_);
       }
 
@@ -1669,7 +1680,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         double *api_barycenters_; size_t api_barycenters_n_;
         gmshModelMeshPreallocateBarycenters(elementType, &api_barycenters_, &api_barycenters_n_, tag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         barycenters.assign(api_barycenters_, api_barycenters_ + api_barycenters_n_); gmshFree(api_barycenters_);
       }
 
@@ -1691,7 +1702,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         size_t *api_nodeTags_; size_t api_nodeTags_n_;
         gmshModelMeshGetElementEdgeNodes(elementType, &api_nodeTags_, &api_nodeTags_n_, tag, (int)primary, task, numTasks, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         nodeTags.assign(api_nodeTags_, api_nodeTags_ + api_nodeTags_n_); gmshFree(api_nodeTags_);
       }
 
@@ -1715,7 +1726,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         size_t *api_nodeTags_; size_t api_nodeTags_n_;
         gmshModelMeshGetElementFaceNodes(elementType, faceType, &api_nodeTags_, &api_nodeTags_n_, tag, (int)primary, task, numTasks, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         nodeTags.assign(api_nodeTags_, api_nodeTags_ + api_nodeTags_n_); gmshFree(api_nodeTags_);
       }
 
@@ -1730,7 +1741,7 @@ namespace gmsh { // Top-level functions
         size_t *api_elementTags_; size_t api_elementTags_n_;
         int *api_partitions_; size_t api_partitions_n_;
         gmshModelMeshGetGhostElements(dim, tag, &api_elementTags_, &api_elementTags_n_, &api_partitions_, &api_partitions_n_, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         elementTags.assign(api_elementTags_, api_elementTags_ + api_elementTags_n_); gmshFree(api_elementTags_);
         partitions.assign(api_partitions_, api_partitions_ + api_partitions_n_); gmshFree(api_partitions_);
       }
@@ -1743,7 +1754,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_dimTags_; size_t api_dimTags_n_; vectorpair2intptr(dimTags, &api_dimTags_, &api_dimTags_n_);
         gmshModelMeshSetSize(api_dimTags_, api_dimTags_n_, size, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_dimTags_);
       }
 
@@ -1759,7 +1770,7 @@ namespace gmsh { // Top-level functions
         double *api_parametricCoord_; size_t api_parametricCoord_n_; vector2ptr(parametricCoord, &api_parametricCoord_, &api_parametricCoord_n_);
         double *api_sizes_; size_t api_sizes_n_; vector2ptr(sizes, &api_sizes_, &api_sizes_n_);
         gmshModelMeshSetSizeAtParametricPoints(dim, tag, api_parametricCoord_, api_parametricCoord_n_, api_sizes_, api_sizes_n_, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_parametricCoord_);
         gmshFree(api_sizes_);
       }
@@ -1775,7 +1786,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         gmshModelMeshSetTransfiniteCurve(tag, numNodes, meshType.c_str(), coef, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
       }
 
       // Set a transfinite meshing constraint on the surface `tag'. `arrangement'
@@ -1792,7 +1803,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_cornerTags_; size_t api_cornerTags_n_; vector2ptr(cornerTags, &api_cornerTags_, &api_cornerTags_n_);
         gmshModelMeshSetTransfiniteSurface(tag, arrangement.c_str(), api_cornerTags_, api_cornerTags_n_, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_cornerTags_);
       }
 
@@ -1805,7 +1816,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_cornerTags_; size_t api_cornerTags_n_; vector2ptr(cornerTags, &api_cornerTags_, &api_cornerTags_n_);
         gmshModelMeshSetTransfiniteVolume(tag, api_cornerTags_, api_cornerTags_n_, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_cornerTags_);
       }
 
@@ -1817,7 +1828,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         gmshModelMeshSetRecombine(dim, tag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
       }
 
       // Set a smoothing meshing constraint on the model entity of dimension `dim'
@@ -1828,7 +1839,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         gmshModelMeshSetSmoothing(dim, tag, val, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
       }
 
       // Set a reverse meshing constraint on the model entity of dimension `dim'
@@ -1842,7 +1853,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         gmshModelMeshSetReverse(dim, tag, (int)val, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
       }
 
       // Set the meshing algorithm on the model entity of dimension `dim' and tag
@@ -1853,7 +1864,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         gmshModelMeshSetAlgorithm(dim, tag, val, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
       }
 
       // Force the mesh size to be extended from the boundary, or not, for the
@@ -1865,7 +1876,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         gmshModelMeshSetSizeFromBoundary(dim, tag, val, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
       }
 
       // Set a compound meshing constraint on the model entities of dimension `dim'
@@ -1877,7 +1888,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_tags_; size_t api_tags_n_; vector2ptr(tags, &api_tags_, &api_tags_n_);
         gmshModelMeshSetCompound(dim, api_tags_, api_tags_n_, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_tags_);
       }
 
@@ -1889,7 +1900,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         gmshModelMeshSetOutwardOrientation(tag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
       }
 
       // Embed the model entities of dimension `dim' and tags `tags' in the
@@ -1905,7 +1916,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_tags_; size_t api_tags_n_; vector2ptr(tags, &api_tags_, &api_tags_n_);
         gmshModelMeshEmbed(dim, api_tags_, api_tags_n_, inDim, inTag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_tags_);
       }
 
@@ -1918,7 +1929,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_dimTags_; size_t api_dimTags_n_; vectorpair2intptr(dimTags, &api_dimTags_, &api_dimTags_n_);
         gmshModelMeshRemoveEmbedded(api_dimTags_, api_dimTags_n_, dim, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_dimTags_);
       }
 
@@ -1931,7 +1942,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         size_t *api_ordering_; size_t api_ordering_n_; vector2ptr(ordering, &api_ordering_, &api_ordering_n_);
         gmshModelMeshReorderElements(elementType, tag, api_ordering_, api_ordering_n_, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_ordering_);
       }
 
@@ -1940,7 +1951,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         gmshModelMeshRenumberNodes(&ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
       }
 
       // Renumber the element tags in a continuous sequence.
@@ -1948,7 +1959,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         gmshModelMeshRenumberElements(&ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
       }
 
       // Set the meshes of the entities of dimension `dim' and tag `tags' as
@@ -1969,7 +1980,7 @@ namespace gmsh { // Top-level functions
         int *api_tagsMaster_; size_t api_tagsMaster_n_; vector2ptr(tagsMaster, &api_tagsMaster_, &api_tagsMaster_n_);
         double *api_affineTransform_; size_t api_affineTransform_n_; vector2ptr(affineTransform, &api_affineTransform_, &api_affineTransform_n_);
         gmshModelMeshSetPeriodic(dim, api_tags_, api_tags_n_, api_tagsMaster_, api_tagsMaster_n_, api_affineTransform_, api_affineTransform_n_, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_tags_);
         gmshFree(api_tagsMaster_);
         gmshFree(api_affineTransform_);
@@ -1993,7 +2004,7 @@ namespace gmsh { // Top-level functions
         size_t *api_nodeTagsMaster_; size_t api_nodeTagsMaster_n_;
         double *api_affineTransform_; size_t api_affineTransform_n_;
         gmshModelMeshGetPeriodicNodes(dim, tag, &tagMaster, &api_nodeTags_, &api_nodeTags_n_, &api_nodeTagsMaster_, &api_nodeTagsMaster_n_, &api_affineTransform_, &api_affineTransform_n_, (int)includeHighOrderNodes, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         nodeTags.assign(api_nodeTags_, api_nodeTags_ + api_nodeTags_n_); gmshFree(api_nodeTags_);
         nodeTagsMaster.assign(api_nodeTagsMaster_, api_nodeTagsMaster_ + api_nodeTagsMaster_n_); gmshFree(api_nodeTagsMaster_);
         affineTransform.assign(api_affineTransform_, api_affineTransform_ + api_affineTransform_n_); gmshFree(api_affineTransform_);
@@ -2004,7 +2015,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         gmshModelMeshRemoveDuplicateNodes(&ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
       }
 
       // Split (into two triangles) all quadrangles in surface `tag' whose quality
@@ -2014,7 +2025,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         gmshModelMeshSplitQuadrangles(quality, tag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
       }
 
       // Classify ("color") the surface mesh based on the angle threshold `angle'
@@ -2031,7 +2042,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         gmshModelMeshClassifySurfaces(angle, (int)boundary, (int)forReparametrization, curveAngle, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
       }
 
       // Create a geometry for the discrete entities `dimTags' (represented solely
@@ -2044,7 +2055,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_dimTags_; size_t api_dimTags_n_; vectorpair2intptr(dimTags, &api_dimTags_, &api_dimTags_n_);
         gmshModelMeshCreateGeometry(api_dimTags_, api_dimTags_n_, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_dimTags_);
       }
 
@@ -2059,7 +2070,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         gmshModelMeshCreateTopology((int)makeSimplyConnected, (int)exportDiscrete, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
       }
 
       // Compute a basis representation for homology spaces after a mesh has been
@@ -2079,7 +2090,7 @@ namespace gmsh { // Top-level functions
         int *api_subdomainTags_; size_t api_subdomainTags_n_; vector2ptr(subdomainTags, &api_subdomainTags_, &api_subdomainTags_n_);
         int *api_dims_; size_t api_dims_n_; vector2ptr(dims, &api_dims_, &api_dims_n_);
         gmshModelMeshComputeHomology(api_domainTags_, api_domainTags_n_, api_subdomainTags_, api_subdomainTags_n_, api_dims_, api_dims_n_, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_domainTags_);
         gmshFree(api_subdomainTags_);
         gmshFree(api_dims_);
@@ -2102,7 +2113,7 @@ namespace gmsh { // Top-level functions
         int *api_subdomainTags_; size_t api_subdomainTags_n_; vector2ptr(subdomainTags, &api_subdomainTags_, &api_subdomainTags_n_);
         int *api_dims_; size_t api_dims_n_; vector2ptr(dims, &api_dims_, &api_dims_n_);
         gmshModelMeshComputeCohomology(api_domainTags_, api_domainTags_n_, api_subdomainTags_, api_subdomainTags_n_, api_dims_, api_dims_n_, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_domainTags_);
         gmshFree(api_subdomainTags_);
         gmshFree(api_dims_);
@@ -2116,7 +2127,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_viewTags_; size_t api_viewTags_n_;
         gmshModelMeshComputeCrossField(&api_viewTags_, &api_viewTags_n_, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         viewTags.assign(api_viewTags_, api_viewTags_ + api_viewTags_n_); gmshFree(api_viewTags_);
       }
 
@@ -2130,7 +2141,7 @@ namespace gmsh { // Top-level functions
         {
           int ierr = 0;
           int result_api_ = gmshModelMeshFieldAdd(fieldType.c_str(), tag, &ierr);
-          if(ierr) throw ierr;
+          if(ierr) throwLastError();
           return result_api_;
         }
 
@@ -2139,7 +2150,7 @@ namespace gmsh { // Top-level functions
         {
           int ierr = 0;
           gmshModelMeshFieldRemove(tag, &ierr);
-          if(ierr) throw ierr;
+          if(ierr) throwLastError();
         }
 
         // Set the numerical option `option' to value `value' for field `tag'.
@@ -2149,7 +2160,7 @@ namespace gmsh { // Top-level functions
         {
           int ierr = 0;
           gmshModelMeshFieldSetNumber(tag, option.c_str(), value, &ierr);
-          if(ierr) throw ierr;
+          if(ierr) throwLastError();
         }
 
         // Set the string option `option' to value `value' for field `tag'.
@@ -2159,7 +2170,7 @@ namespace gmsh { // Top-level functions
         {
           int ierr = 0;
           gmshModelMeshFieldSetString(tag, option.c_str(), value.c_str(), &ierr);
-          if(ierr) throw ierr;
+          if(ierr) throwLastError();
         }
 
         // Set the numerical list option `option' to value `value' for field `tag'.
@@ -2170,7 +2181,7 @@ namespace gmsh { // Top-level functions
           int ierr = 0;
           double *api_value_; size_t api_value_n_; vector2ptr(value, &api_value_, &api_value_n_);
           gmshModelMeshFieldSetNumbers(tag, option.c_str(), api_value_, api_value_n_, &ierr);
-          if(ierr) throw ierr;
+          if(ierr) throwLastError();
           gmshFree(api_value_);
         }
 
@@ -2179,7 +2190,7 @@ namespace gmsh { // Top-level functions
         {
           int ierr = 0;
           gmshModelMeshFieldSetAsBackgroundMesh(tag, &ierr);
-          if(ierr) throw ierr;
+          if(ierr) throwLastError();
         }
 
         // Set the field `tag' as a boundary layer size field.
@@ -2187,7 +2198,7 @@ namespace gmsh { // Top-level functions
         {
           int ierr = 0;
           gmshModelMeshFieldSetAsBoundaryLayer(tag, &ierr);
-          if(ierr) throw ierr;
+          if(ierr) throwLastError();
         }
 
       } // namespace field
@@ -2210,7 +2221,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         int result_api_ = gmshModelGeoAddPoint(x, y, z, meshSize, tag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         return result_api_;
       }
 
@@ -2223,7 +2234,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         int result_api_ = gmshModelGeoAddLine(startTag, endTag, tag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         return result_api_;
       }
 
@@ -2242,7 +2253,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         int result_api_ = gmshModelGeoAddCircleArc(startTag, centerTag, endTag, tag, nx, ny, nz, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         return result_api_;
       }
 
@@ -2263,7 +2274,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         int result_api_ = gmshModelGeoAddEllipseArc(startTag, centerTag, majorTag, endTag, tag, nx, ny, nz, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         return result_api_;
       }
 
@@ -2277,7 +2288,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_pointTags_; size_t api_pointTags_n_; vector2ptr(pointTags, &api_pointTags_, &api_pointTags_n_);
         int result_api_ = gmshModelGeoAddSpline(api_pointTags_, api_pointTags_n_, tag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_pointTags_);
         return result_api_;
       }
@@ -2292,7 +2303,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_pointTags_; size_t api_pointTags_n_; vector2ptr(pointTags, &api_pointTags_, &api_pointTags_n_);
         int result_api_ = gmshModelGeoAddBSpline(api_pointTags_, api_pointTags_n_, tag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_pointTags_);
         return result_api_;
       }
@@ -2306,7 +2317,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_pointTags_; size_t api_pointTags_n_; vector2ptr(pointTags, &api_pointTags_, &api_pointTags_n_);
         int result_api_ = gmshModelGeoAddBezier(api_pointTags_, api_pointTags_n_, tag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_pointTags_);
         return result_api_;
       }
@@ -2321,7 +2332,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_pointTags_; size_t api_pointTags_n_; vector2ptr(pointTags, &api_pointTags_, &api_pointTags_n_);
         int result_api_ = gmshModelGeoAddPolyline(api_pointTags_, api_pointTags_n_, tag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_pointTags_);
         return result_api_;
       }
@@ -2337,7 +2348,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_curveTags_; size_t api_curveTags_n_; vector2ptr(curveTags, &api_curveTags_, &api_curveTags_n_);
         int result_api_ = gmshModelGeoAddCompoundSpline(api_curveTags_, api_curveTags_n_, numIntervals, tag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_curveTags_);
         return result_api_;
       }
@@ -2353,7 +2364,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_curveTags_; size_t api_curveTags_n_; vector2ptr(curveTags, &api_curveTags_, &api_curveTags_n_);
         int result_api_ = gmshModelGeoAddCompoundBSpline(api_curveTags_, api_curveTags_n_, numIntervals, tag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_curveTags_);
         return result_api_;
       }
@@ -2370,7 +2381,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_curveTags_; size_t api_curveTags_n_; vector2ptr(curveTags, &api_curveTags_, &api_curveTags_n_);
         int result_api_ = gmshModelGeoAddCurveLoop(api_curveTags_, api_curveTags_n_, tag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_curveTags_);
         return result_api_;
       }
@@ -2385,7 +2396,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_wireTags_; size_t api_wireTags_n_; vector2ptr(wireTags, &api_wireTags_, &api_wireTags_n_);
         int result_api_ = gmshModelGeoAddPlaneSurface(api_wireTags_, api_wireTags_n_, tag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_wireTags_);
         return result_api_;
       }
@@ -2401,7 +2412,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_wireTags_; size_t api_wireTags_n_; vector2ptr(wireTags, &api_wireTags_, &api_wireTags_n_);
         int result_api_ = gmshModelGeoAddSurfaceFilling(api_wireTags_, api_wireTags_n_, tag, sphereCenterTag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_wireTags_);
         return result_api_;
       }
@@ -2415,7 +2426,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_surfaceTags_; size_t api_surfaceTags_n_; vector2ptr(surfaceTags, &api_surfaceTags_, &api_surfaceTags_n_);
         int result_api_ = gmshModelGeoAddSurfaceLoop(api_surfaceTags_, api_surfaceTags_n_, tag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_surfaceTags_);
         return result_api_;
       }
@@ -2430,7 +2441,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_shellTags_; size_t api_shellTags_n_; vector2ptr(shellTags, &api_shellTags_, &api_shellTags_n_);
         int result_api_ = gmshModelGeoAddVolume(api_shellTags_, api_shellTags_n_, tag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_shellTags_);
         return result_api_;
       }
@@ -2456,7 +2467,7 @@ namespace gmsh { // Top-level functions
         int *api_numElements_; size_t api_numElements_n_; vector2ptr(numElements, &api_numElements_, &api_numElements_n_);
         double *api_heights_; size_t api_heights_n_; vector2ptr(heights, &api_heights_, &api_heights_n_);
         gmshModelGeoExtrude(api_dimTags_, api_dimTags_n_, dx, dy, dz, &api_outDimTags_, &api_outDimTags_n_, api_numElements_, api_numElements_n_, api_heights_, api_heights_n_, (int)recombine, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_dimTags_);
         outDimTags.resize(api_outDimTags_n_ / 2); for(size_t i = 0; i < api_outDimTags_n_ / 2; ++i){ outDimTags[i].first = api_outDimTags_[i * 2 + 0]; outDimTags[i].second = api_outDimTags_[i * 2 + 1]; } gmshFree(api_outDimTags_);
         gmshFree(api_numElements_);
@@ -2489,7 +2500,7 @@ namespace gmsh { // Top-level functions
         int *api_numElements_; size_t api_numElements_n_; vector2ptr(numElements, &api_numElements_, &api_numElements_n_);
         double *api_heights_; size_t api_heights_n_; vector2ptr(heights, &api_heights_, &api_heights_n_);
         gmshModelGeoRevolve(api_dimTags_, api_dimTags_n_, x, y, z, ax, ay, az, angle, &api_outDimTags_, &api_outDimTags_n_, api_numElements_, api_numElements_n_, api_heights_, api_heights_n_, (int)recombine, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_dimTags_);
         outDimTags.resize(api_outDimTags_n_ / 2); for(size_t i = 0; i < api_outDimTags_n_ / 2; ++i){ outDimTags[i].first = api_outDimTags_[i * 2 + 0]; outDimTags[i].second = api_outDimTags_[i * 2 + 1]; } gmshFree(api_outDimTags_);
         gmshFree(api_numElements_);
@@ -2526,7 +2537,7 @@ namespace gmsh { // Top-level functions
         int *api_numElements_; size_t api_numElements_n_; vector2ptr(numElements, &api_numElements_, &api_numElements_n_);
         double *api_heights_; size_t api_heights_n_; vector2ptr(heights, &api_heights_, &api_heights_n_);
         gmshModelGeoTwist(api_dimTags_, api_dimTags_n_, x, y, z, dx, dy, dz, ax, ay, az, angle, &api_outDimTags_, &api_outDimTags_n_, api_numElements_, api_numElements_n_, api_heights_, api_heights_n_, (int)recombine, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_dimTags_);
         outDimTags.resize(api_outDimTags_n_ / 2); for(size_t i = 0; i < api_outDimTags_n_ / 2; ++i){ outDimTags[i].first = api_outDimTags_[i * 2 + 0]; outDimTags[i].second = api_outDimTags_[i * 2 + 1]; } gmshFree(api_outDimTags_);
         gmshFree(api_numElements_);
@@ -2542,7 +2553,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_dimTags_; size_t api_dimTags_n_; vectorpair2intptr(dimTags, &api_dimTags_, &api_dimTags_n_);
         gmshModelGeoTranslate(api_dimTags_, api_dimTags_n_, dx, dy, dz, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_dimTags_);
       }
 
@@ -2561,7 +2572,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_dimTags_; size_t api_dimTags_n_; vectorpair2intptr(dimTags, &api_dimTags_, &api_dimTags_n_);
         gmshModelGeoRotate(api_dimTags_, api_dimTags_n_, x, y, z, ax, ay, az, angle, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_dimTags_);
       }
 
@@ -2579,7 +2590,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_dimTags_; size_t api_dimTags_n_; vectorpair2intptr(dimTags, &api_dimTags_, &api_dimTags_n_);
         gmshModelGeoDilate(api_dimTags_, api_dimTags_n_, x, y, z, a, b, c, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_dimTags_);
       }
 
@@ -2594,7 +2605,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_dimTags_; size_t api_dimTags_n_; vectorpair2intptr(dimTags, &api_dimTags_, &api_dimTags_n_);
         gmshModelGeoMirror(api_dimTags_, api_dimTags_n_, a, b, c, d, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_dimTags_);
       }
 
@@ -2610,7 +2621,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_dimTags_; size_t api_dimTags_n_; vectorpair2intptr(dimTags, &api_dimTags_, &api_dimTags_n_);
         gmshModelGeoSymmetrize(api_dimTags_, api_dimTags_n_, a, b, c, d, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_dimTags_);
       }
 
@@ -2623,7 +2634,7 @@ namespace gmsh { // Top-level functions
         int *api_dimTags_; size_t api_dimTags_n_; vectorpair2intptr(dimTags, &api_dimTags_, &api_dimTags_n_);
         int *api_outDimTags_; size_t api_outDimTags_n_;
         gmshModelGeoCopy(api_dimTags_, api_dimTags_n_, &api_outDimTags_, &api_outDimTags_n_, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_dimTags_);
         outDimTags.resize(api_outDimTags_n_ / 2); for(size_t i = 0; i < api_outDimTags_n_ / 2; ++i){ outDimTags[i].first = api_outDimTags_[i * 2 + 0]; outDimTags[i].second = api_outDimTags_[i * 2 + 1]; } gmshFree(api_outDimTags_);
       }
@@ -2636,7 +2647,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_dimTags_; size_t api_dimTags_n_; vectorpair2intptr(dimTags, &api_dimTags_, &api_dimTags_n_);
         gmshModelGeoRemove(api_dimTags_, api_dimTags_n_, (int)recursive, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_dimTags_);
       }
 
@@ -2646,7 +2657,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         gmshModelGeoRemoveAllDuplicates(&ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
       }
 
       // Split the model curve of tag `tag' on the control points `pointTags'.
@@ -2659,7 +2670,7 @@ namespace gmsh { // Top-level functions
         int *api_pointTags_; size_t api_pointTags_n_; vector2ptr(pointTags, &api_pointTags_, &api_pointTags_n_);
         int *api_curveTags_; size_t api_curveTags_n_;
         gmshModelGeoSplitCurve(tag, api_pointTags_, api_pointTags_n_, &api_curveTags_, &api_curveTags_n_, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_pointTags_);
         curveTags.assign(api_curveTags_, api_curveTags_ + api_curveTags_n_); gmshFree(api_curveTags_);
       }
@@ -2670,7 +2681,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         int result_api_ = gmshModelGeoGetMaxTag(dim, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         return result_api_;
       }
 
@@ -2681,7 +2692,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         gmshModelGeoSetMaxTag(dim, maxTag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
       }
 
       // Synchronize the built-in CAD representation with the current Gmsh model.
@@ -2692,7 +2703,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         gmshModelGeoSynchronize(&ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
       }
 
       namespace mesh { // Built-in CAD kernel meshing constraints
@@ -2705,7 +2716,7 @@ namespace gmsh { // Top-level functions
           int ierr = 0;
           int *api_dimTags_; size_t api_dimTags_n_; vectorpair2intptr(dimTags, &api_dimTags_, &api_dimTags_n_);
           gmshModelGeoMeshSetSize(api_dimTags_, api_dimTags_n_, size, &ierr);
-          if(ierr) throw ierr;
+          if(ierr) throwLastError();
           gmshFree(api_dimTags_);
         }
 
@@ -2720,7 +2731,7 @@ namespace gmsh { // Top-level functions
         {
           int ierr = 0;
           gmshModelGeoMeshSetTransfiniteCurve(tag, nPoints, meshType.c_str(), coef, &ierr);
-          if(ierr) throw ierr;
+          if(ierr) throwLastError();
         }
 
         // Set a transfinite meshing constraint on the surface `tag'. `arrangement'
@@ -2737,7 +2748,7 @@ namespace gmsh { // Top-level functions
           int ierr = 0;
           int *api_cornerTags_; size_t api_cornerTags_n_; vector2ptr(cornerTags, &api_cornerTags_, &api_cornerTags_n_);
           gmshModelGeoMeshSetTransfiniteSurface(tag, arrangement.c_str(), api_cornerTags_, api_cornerTags_n_, &ierr);
-          if(ierr) throw ierr;
+          if(ierr) throwLastError();
           gmshFree(api_cornerTags_);
         }
 
@@ -2750,7 +2761,7 @@ namespace gmsh { // Top-level functions
           int ierr = 0;
           int *api_cornerTags_; size_t api_cornerTags_n_; vector2ptr(cornerTags, &api_cornerTags_, &api_cornerTags_n_);
           gmshModelGeoMeshSetTransfiniteVolume(tag, api_cornerTags_, api_cornerTags_n_, &ierr);
-          if(ierr) throw ierr;
+          if(ierr) throwLastError();
           gmshFree(api_cornerTags_);
         }
 
@@ -2763,7 +2774,7 @@ namespace gmsh { // Top-level functions
         {
           int ierr = 0;
           gmshModelGeoMeshSetRecombine(dim, tag, angle, &ierr);
-          if(ierr) throw ierr;
+          if(ierr) throwLastError();
         }
 
         // Set a smoothing meshing constraint on the model entity of dimension
@@ -2774,7 +2785,7 @@ namespace gmsh { // Top-level functions
         {
           int ierr = 0;
           gmshModelGeoMeshSetSmoothing(dim, tag, val, &ierr);
-          if(ierr) throw ierr;
+          if(ierr) throwLastError();
         }
 
         // Set a reverse meshing constraint on the model entity of dimension `dim'
@@ -2788,7 +2799,7 @@ namespace gmsh { // Top-level functions
         {
           int ierr = 0;
           gmshModelGeoMeshSetReverse(dim, tag, (int)val, &ierr);
-          if(ierr) throw ierr;
+          if(ierr) throwLastError();
         }
 
         // Set the meshing algorithm on the model entity of dimension `dim' and tag
@@ -2799,7 +2810,7 @@ namespace gmsh { // Top-level functions
         {
           int ierr = 0;
           gmshModelGeoMeshSetAlgorithm(dim, tag, val, &ierr);
-          if(ierr) throw ierr;
+          if(ierr) throwLastError();
         }
 
         // Force the mesh size to be extended from the boundary, or not, for the
@@ -2811,7 +2822,7 @@ namespace gmsh { // Top-level functions
         {
           int ierr = 0;
           gmshModelGeoMeshSetSizeFromBoundary(dim, tag, val, &ierr);
-          if(ierr) throw ierr;
+          if(ierr) throwLastError();
         }
 
       } // namespace mesh
@@ -2835,7 +2846,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         int result_api_ = gmshModelOccAddPoint(x, y, z, meshSize, tag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         return result_api_;
       }
 
@@ -2848,7 +2859,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         int result_api_ = gmshModelOccAddLine(startTag, endTag, tag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         return result_api_;
       }
 
@@ -2863,7 +2874,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         int result_api_ = gmshModelOccAddCircleArc(startTag, centerTag, endTag, tag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         return result_api_;
       }
 
@@ -2881,7 +2892,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         int result_api_ = gmshModelOccAddCircle(x, y, z, r, tag, angle1, angle2, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         return result_api_;
       }
 
@@ -2898,7 +2909,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         int result_api_ = gmshModelOccAddEllipseArc(startTag, centerTag, majorTag, endTag, tag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         return result_api_;
       }
 
@@ -2921,7 +2932,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         int result_api_ = gmshModelOccAddEllipse(x, y, z, r1, r2, tag, angle1, angle2, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         return result_api_;
       }
 
@@ -2935,7 +2946,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_pointTags_; size_t api_pointTags_n_; vector2ptr(pointTags, &api_pointTags_, &api_pointTags_n_);
         int result_api_ = gmshModelOccAddSpline(api_pointTags_, api_pointTags_n_, tag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_pointTags_);
         return result_api_;
       }
@@ -2959,7 +2970,7 @@ namespace gmsh { // Top-level functions
         double *api_knots_; size_t api_knots_n_; vector2ptr(knots, &api_knots_, &api_knots_n_);
         int *api_multiplicities_; size_t api_multiplicities_n_; vector2ptr(multiplicities, &api_multiplicities_, &api_multiplicities_n_);
         int result_api_ = gmshModelOccAddBSpline(api_pointTags_, api_pointTags_n_, tag, degree, api_weights_, api_weights_n_, api_knots_, api_knots_n_, api_multiplicities_, api_multiplicities_n_, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_pointTags_);
         gmshFree(api_weights_);
         gmshFree(api_knots_);
@@ -2976,7 +2987,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_pointTags_; size_t api_pointTags_n_; vector2ptr(pointTags, &api_pointTags_, &api_pointTags_n_);
         int result_api_ = gmshModelOccAddBezier(api_pointTags_, api_pointTags_n_, tag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_pointTags_);
         return result_api_;
       }
@@ -2993,7 +3004,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_curveTags_; size_t api_curveTags_n_; vector2ptr(curveTags, &api_curveTags_, &api_curveTags_n_);
         int result_api_ = gmshModelOccAddWire(api_curveTags_, api_curveTags_n_, tag, (int)checkClosed, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_curveTags_);
         return result_api_;
       }
@@ -3010,7 +3021,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_curveTags_; size_t api_curveTags_n_; vector2ptr(curveTags, &api_curveTags_, &api_curveTags_n_);
         int result_api_ = gmshModelOccAddCurveLoop(api_curveTags_, api_curveTags_n_, tag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_curveTags_);
         return result_api_;
       }
@@ -3029,7 +3040,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         int result_api_ = gmshModelOccAddRectangle(x, y, z, dx, dy, tag, roundedRadius, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         return result_api_;
       }
 
@@ -3045,7 +3056,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         int result_api_ = gmshModelOccAddDisk(xc, yc, zc, rx, ry, tag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         return result_api_;
       }
 
@@ -3060,7 +3071,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_wireTags_; size_t api_wireTags_n_; vector2ptr(wireTags, &api_wireTags_, &api_wireTags_n_);
         int result_api_ = gmshModelOccAddPlaneSurface(api_wireTags_, api_wireTags_n_, tag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_wireTags_);
         return result_api_;
       }
@@ -3076,7 +3087,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_pointTags_; size_t api_pointTags_n_; vector2ptr(pointTags, &api_pointTags_, &api_pointTags_n_);
         int result_api_ = gmshModelOccAddSurfaceFilling(wireTag, tag, api_pointTags_, api_pointTags_n_, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_pointTags_);
         return result_api_;
       }
@@ -3094,7 +3105,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         int result_api_ = gmshModelOccAddBSplineFilling(wireTag, tag, type.c_str(), &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         return result_api_;
       }
 
@@ -3111,7 +3122,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         int result_api_ = gmshModelOccAddBezierFilling(wireTag, tag, type.c_str(), &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         return result_api_;
       }
 
@@ -3140,7 +3151,7 @@ namespace gmsh { // Top-level functions
         int *api_multiplicitiesU_; size_t api_multiplicitiesU_n_; vector2ptr(multiplicitiesU, &api_multiplicitiesU_, &api_multiplicitiesU_n_);
         int *api_multiplicitiesV_; size_t api_multiplicitiesV_n_; vector2ptr(multiplicitiesV, &api_multiplicitiesV_, &api_multiplicitiesV_n_);
         int result_api_ = gmshModelOccAddBSplineSurface(api_pointTags_, api_pointTags_n_, numPointsU, tag, degreeU, degreeV, api_weights_, api_weights_n_, api_knotsU_, api_knotsU_n_, api_knotsV_, api_knotsV_n_, api_multiplicitiesU_, api_multiplicitiesU_n_, api_multiplicitiesV_, api_multiplicitiesV_n_, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_pointTags_);
         gmshFree(api_weights_);
         gmshFree(api_knotsU_);
@@ -3161,7 +3172,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_pointTags_; size_t api_pointTags_n_; vector2ptr(pointTags, &api_pointTags_, &api_pointTags_n_);
         int result_api_ = gmshModelOccAddBezierSurface(api_pointTags_, api_pointTags_n_, numPointsU, tag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_pointTags_);
         return result_api_;
       }
@@ -3178,7 +3189,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_surfaceTags_; size_t api_surfaceTags_n_; vector2ptr(surfaceTags, &api_surfaceTags_, &api_surfaceTags_n_);
         int result_api_ = gmshModelOccAddSurfaceLoop(api_surfaceTags_, api_surfaceTags_n_, tag, (int)sewing, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_surfaceTags_);
         return result_api_;
       }
@@ -3193,7 +3204,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_shellTags_; size_t api_shellTags_n_; vector2ptr(shellTags, &api_shellTags_, &api_shellTags_n_);
         int result_api_ = gmshModelOccAddVolume(api_shellTags_, api_shellTags_n_, tag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_shellTags_);
         return result_api_;
       }
@@ -3214,7 +3225,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         int result_api_ = gmshModelOccAddSphere(xc, yc, zc, radius, tag, angle1, angle2, angle3, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         return result_api_;
       }
 
@@ -3232,7 +3243,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         int result_api_ = gmshModelOccAddBox(x, y, z, dx, dy, dz, tag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         return result_api_;
       }
 
@@ -3254,7 +3265,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         int result_api_ = gmshModelOccAddCylinder(x, y, z, dx, dy, dz, r, tag, angle, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         return result_api_;
       }
 
@@ -3277,7 +3288,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         int result_api_ = gmshModelOccAddCone(x, y, z, dx, dy, dz, r1, r2, tag, angle, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         return result_api_;
       }
 
@@ -3297,7 +3308,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         int result_api_ = gmshModelOccAddWedge(x, y, z, dx, dy, dz, tag, ltx, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         return result_api_;
       }
 
@@ -3315,7 +3326,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         int result_api_ = gmshModelOccAddTorus(x, y, z, r1, r2, tag, angle, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         return result_api_;
       }
 
@@ -3337,7 +3348,7 @@ namespace gmsh { // Top-level functions
         int *api_wireTags_; size_t api_wireTags_n_; vector2ptr(wireTags, &api_wireTags_, &api_wireTags_n_);
         int *api_outDimTags_; size_t api_outDimTags_n_;
         gmshModelOccAddThruSections(api_wireTags_, api_wireTags_n_, &api_outDimTags_, &api_outDimTags_n_, tag, (int)makeSolid, (int)makeRuled, maxDegree, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_wireTags_);
         outDimTags.resize(api_outDimTags_n_ / 2); for(size_t i = 0; i < api_outDimTags_n_ / 2; ++i){ outDimTags[i].first = api_outDimTags_[i * 2 + 0]; outDimTags[i].second = api_outDimTags_[i * 2 + 1]; } gmshFree(api_outDimTags_);
       }
@@ -3357,7 +3368,7 @@ namespace gmsh { // Top-level functions
         int *api_excludeSurfaceTags_; size_t api_excludeSurfaceTags_n_; vector2ptr(excludeSurfaceTags, &api_excludeSurfaceTags_, &api_excludeSurfaceTags_n_);
         int *api_outDimTags_; size_t api_outDimTags_n_;
         gmshModelOccAddThickSolid(volumeTag, api_excludeSurfaceTags_, api_excludeSurfaceTags_n_, offset, &api_outDimTags_, &api_outDimTags_n_, tag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_excludeSurfaceTags_);
         outDimTags.resize(api_outDimTags_n_ / 2); for(size_t i = 0; i < api_outDimTags_n_ / 2; ++i){ outDimTags[i].first = api_outDimTags_[i * 2 + 0]; outDimTags[i].second = api_outDimTags_[i * 2 + 1]; } gmshFree(api_outDimTags_);
       }
@@ -3382,7 +3393,7 @@ namespace gmsh { // Top-level functions
         int *api_numElements_; size_t api_numElements_n_; vector2ptr(numElements, &api_numElements_, &api_numElements_n_);
         double *api_heights_; size_t api_heights_n_; vector2ptr(heights, &api_heights_, &api_heights_n_);
         gmshModelOccExtrude(api_dimTags_, api_dimTags_n_, dx, dy, dz, &api_outDimTags_, &api_outDimTags_n_, api_numElements_, api_numElements_n_, api_heights_, api_heights_n_, (int)recombine, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_dimTags_);
         outDimTags.resize(api_outDimTags_n_ / 2); for(size_t i = 0; i < api_outDimTags_n_ / 2; ++i){ outDimTags[i].first = api_outDimTags_[i * 2 + 0]; outDimTags[i].second = api_outDimTags_[i * 2 + 1]; } gmshFree(api_outDimTags_);
         gmshFree(api_numElements_);
@@ -3416,7 +3427,7 @@ namespace gmsh { // Top-level functions
         int *api_numElements_; size_t api_numElements_n_; vector2ptr(numElements, &api_numElements_, &api_numElements_n_);
         double *api_heights_; size_t api_heights_n_; vector2ptr(heights, &api_heights_, &api_heights_n_);
         gmshModelOccRevolve(api_dimTags_, api_dimTags_n_, x, y, z, ax, ay, az, angle, &api_outDimTags_, &api_outDimTags_n_, api_numElements_, api_numElements_n_, api_heights_, api_heights_n_, (int)recombine, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_dimTags_);
         outDimTags.resize(api_outDimTags_n_ / 2); for(size_t i = 0; i < api_outDimTags_n_ / 2; ++i){ outDimTags[i].first = api_outDimTags_[i * 2 + 0]; outDimTags[i].second = api_outDimTags_[i * 2 + 1]; } gmshFree(api_outDimTags_);
         gmshFree(api_numElements_);
@@ -3433,7 +3444,7 @@ namespace gmsh { // Top-level functions
         int *api_dimTags_; size_t api_dimTags_n_; vectorpair2intptr(dimTags, &api_dimTags_, &api_dimTags_n_);
         int *api_outDimTags_; size_t api_outDimTags_n_;
         gmshModelOccAddPipe(api_dimTags_, api_dimTags_n_, wireTag, &api_outDimTags_, &api_outDimTags_n_, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_dimTags_);
         outDimTags.resize(api_outDimTags_n_ / 2); for(size_t i = 0; i < api_outDimTags_n_ / 2; ++i){ outDimTags[i].first = api_outDimTags_[i * 2 + 0]; outDimTags[i].second = api_outDimTags_[i * 2 + 1]; } gmshFree(api_outDimTags_);
       }
@@ -3456,7 +3467,7 @@ namespace gmsh { // Top-level functions
         double *api_radii_; size_t api_radii_n_; vector2ptr(radii, &api_radii_, &api_radii_n_);
         int *api_outDimTags_; size_t api_outDimTags_n_;
         gmshModelOccFillet(api_volumeTags_, api_volumeTags_n_, api_curveTags_, api_curveTags_n_, api_radii_, api_radii_n_, &api_outDimTags_, &api_outDimTags_n_, (int)removeVolume, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_volumeTags_);
         gmshFree(api_curveTags_);
         gmshFree(api_radii_);
@@ -3485,7 +3496,7 @@ namespace gmsh { // Top-level functions
         double *api_distances_; size_t api_distances_n_; vector2ptr(distances, &api_distances_, &api_distances_n_);
         int *api_outDimTags_; size_t api_outDimTags_n_;
         gmshModelOccChamfer(api_volumeTags_, api_volumeTags_n_, api_curveTags_, api_curveTags_n_, api_surfaceTags_, api_surfaceTags_n_, api_distances_, api_distances_n_, &api_outDimTags_, &api_outDimTags_n_, (int)removeVolume, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_volumeTags_);
         gmshFree(api_curveTags_);
         gmshFree(api_surfaceTags_);
@@ -3512,7 +3523,7 @@ namespace gmsh { // Top-level functions
         int *api_outDimTags_; size_t api_outDimTags_n_;
         int **api_outDimTagsMap_; size_t *api_outDimTagsMap_n_, api_outDimTagsMap_nn_;
         gmshModelOccFuse(api_objectDimTags_, api_objectDimTags_n_, api_toolDimTags_, api_toolDimTags_n_, &api_outDimTags_, &api_outDimTags_n_, &api_outDimTagsMap_, &api_outDimTagsMap_n_, &api_outDimTagsMap_nn_, tag, (int)removeObject, (int)removeTool, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_objectDimTags_);
         gmshFree(api_toolDimTags_);
         outDimTags.resize(api_outDimTags_n_ / 2); for(size_t i = 0; i < api_outDimTags_n_ / 2; ++i){ outDimTags[i].first = api_outDimTags_[i * 2 + 0]; outDimTags[i].second = api_outDimTags_[i * 2 + 1]; } gmshFree(api_outDimTags_);
@@ -3538,7 +3549,7 @@ namespace gmsh { // Top-level functions
         int *api_outDimTags_; size_t api_outDimTags_n_;
         int **api_outDimTagsMap_; size_t *api_outDimTagsMap_n_, api_outDimTagsMap_nn_;
         gmshModelOccIntersect(api_objectDimTags_, api_objectDimTags_n_, api_toolDimTags_, api_toolDimTags_n_, &api_outDimTags_, &api_outDimTags_n_, &api_outDimTagsMap_, &api_outDimTagsMap_n_, &api_outDimTagsMap_nn_, tag, (int)removeObject, (int)removeTool, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_objectDimTags_);
         gmshFree(api_toolDimTags_);
         outDimTags.resize(api_outDimTags_n_ / 2); for(size_t i = 0; i < api_outDimTags_n_ / 2; ++i){ outDimTags[i].first = api_outDimTags_[i * 2 + 0]; outDimTags[i].second = api_outDimTags_[i * 2 + 1]; } gmshFree(api_outDimTags_);
@@ -3564,7 +3575,7 @@ namespace gmsh { // Top-level functions
         int *api_outDimTags_; size_t api_outDimTags_n_;
         int **api_outDimTagsMap_; size_t *api_outDimTagsMap_n_, api_outDimTagsMap_nn_;
         gmshModelOccCut(api_objectDimTags_, api_objectDimTags_n_, api_toolDimTags_, api_toolDimTags_n_, &api_outDimTags_, &api_outDimTags_n_, &api_outDimTagsMap_, &api_outDimTagsMap_n_, &api_outDimTagsMap_nn_, tag, (int)removeObject, (int)removeTool, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_objectDimTags_);
         gmshFree(api_toolDimTags_);
         outDimTags.resize(api_outDimTags_n_ / 2); for(size_t i = 0; i < api_outDimTags_n_ / 2; ++i){ outDimTags[i].first = api_outDimTags_[i * 2 + 0]; outDimTags[i].second = api_outDimTags_[i * 2 + 1]; } gmshFree(api_outDimTags_);
@@ -3590,7 +3601,7 @@ namespace gmsh { // Top-level functions
         int *api_outDimTags_; size_t api_outDimTags_n_;
         int **api_outDimTagsMap_; size_t *api_outDimTagsMap_n_, api_outDimTagsMap_nn_;
         gmshModelOccFragment(api_objectDimTags_, api_objectDimTags_n_, api_toolDimTags_, api_toolDimTags_n_, &api_outDimTags_, &api_outDimTags_n_, &api_outDimTagsMap_, &api_outDimTagsMap_n_, &api_outDimTagsMap_nn_, tag, (int)removeObject, (int)removeTool, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_objectDimTags_);
         gmshFree(api_toolDimTags_);
         outDimTags.resize(api_outDimTags_n_ / 2); for(size_t i = 0; i < api_outDimTags_n_ / 2; ++i){ outDimTags[i].first = api_outDimTags_[i * 2 + 0]; outDimTags[i].second = api_outDimTags_[i * 2 + 1]; } gmshFree(api_outDimTags_);
@@ -3606,7 +3617,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_dimTags_; size_t api_dimTags_n_; vectorpair2intptr(dimTags, &api_dimTags_, &api_dimTags_n_);
         gmshModelOccTranslate(api_dimTags_, api_dimTags_n_, dx, dy, dz, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_dimTags_);
       }
 
@@ -3625,7 +3636,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_dimTags_; size_t api_dimTags_n_; vectorpair2intptr(dimTags, &api_dimTags_, &api_dimTags_n_);
         gmshModelOccRotate(api_dimTags_, api_dimTags_n_, x, y, z, ax, ay, az, angle, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_dimTags_);
       }
 
@@ -3643,7 +3654,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_dimTags_; size_t api_dimTags_n_; vectorpair2intptr(dimTags, &api_dimTags_, &api_dimTags_n_);
         gmshModelOccDilate(api_dimTags_, api_dimTags_n_, x, y, z, a, b, c, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_dimTags_);
       }
 
@@ -3658,7 +3669,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_dimTags_; size_t api_dimTags_n_; vectorpair2intptr(dimTags, &api_dimTags_, &api_dimTags_n_);
         gmshModelOccMirror(api_dimTags_, api_dimTags_n_, a, b, c, d, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_dimTags_);
       }
 
@@ -3675,7 +3686,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_dimTags_; size_t api_dimTags_n_; vectorpair2intptr(dimTags, &api_dimTags_, &api_dimTags_n_);
         gmshModelOccSymmetrize(api_dimTags_, api_dimTags_n_, a, b, c, d, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_dimTags_);
       }
 
@@ -3689,7 +3700,7 @@ namespace gmsh { // Top-level functions
         int *api_dimTags_; size_t api_dimTags_n_; vectorpair2intptr(dimTags, &api_dimTags_, &api_dimTags_n_);
         double *api_a_; size_t api_a_n_; vector2ptr(a, &api_a_, &api_a_n_);
         gmshModelOccAffineTransform(api_dimTags_, api_dimTags_n_, api_a_, api_a_n_, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_dimTags_);
         gmshFree(api_a_);
       }
@@ -3703,7 +3714,7 @@ namespace gmsh { // Top-level functions
         int *api_dimTags_; size_t api_dimTags_n_; vectorpair2intptr(dimTags, &api_dimTags_, &api_dimTags_n_);
         int *api_outDimTags_; size_t api_outDimTags_n_;
         gmshModelOccCopy(api_dimTags_, api_dimTags_n_, &api_outDimTags_, &api_outDimTags_n_, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_dimTags_);
         outDimTags.resize(api_outDimTags_n_ / 2); for(size_t i = 0; i < api_outDimTags_n_ / 2; ++i){ outDimTags[i].first = api_outDimTags_[i * 2 + 0]; outDimTags[i].second = api_outDimTags_[i * 2 + 1]; } gmshFree(api_outDimTags_);
       }
@@ -3716,7 +3727,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_dimTags_; size_t api_dimTags_n_; vectorpair2intptr(dimTags, &api_dimTags_, &api_dimTags_n_);
         gmshModelOccRemove(api_dimTags_, api_dimTags_n_, (int)recursive, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         gmshFree(api_dimTags_);
       }
 
@@ -3727,7 +3738,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         gmshModelOccRemoveAllDuplicates(&ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
       }
 
       // Apply various healing procedures to the entities `dimTags' (or to all the
@@ -3747,7 +3758,7 @@ namespace gmsh { // Top-level functions
         int *api_outDimTags_; size_t api_outDimTags_n_;
         int *api_dimTags_; size_t api_dimTags_n_; vectorpair2intptr(dimTags, &api_dimTags_, &api_dimTags_n_);
         gmshModelOccHealShapes(&api_outDimTags_, &api_outDimTags_n_, api_dimTags_, api_dimTags_n_, tolerance, (int)fixDegenerated, (int)fixSmallEdges, (int)fixSmallFaces, (int)sewFaces, (int)makeSolids, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         outDimTags.resize(api_outDimTags_n_ / 2); for(size_t i = 0; i < api_outDimTags_n_ / 2; ++i){ outDimTags[i].first = api_outDimTags_[i * 2 + 0]; outDimTags[i].second = api_outDimTags_[i * 2 + 1]; } gmshFree(api_outDimTags_);
         gmshFree(api_dimTags_);
       }
@@ -3765,7 +3776,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_outDimTags_; size_t api_outDimTags_n_;
         gmshModelOccImportShapes(fileName.c_str(), &api_outDimTags_, &api_outDimTags_n_, (int)highestDimOnly, format.c_str(), &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         outDimTags.resize(api_outDimTags_n_ / 2); for(size_t i = 0; i < api_outDimTags_n_ / 2; ++i){ outDimTags[i].first = api_outDimTags_[i * 2 + 0]; outDimTags[i].second = api_outDimTags_[i * 2 + 1]; } gmshFree(api_outDimTags_);
       }
 
@@ -3782,7 +3793,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_outDimTags_; size_t api_outDimTags_n_;
         gmshModelOccImportShapesNativePointer(shape, &api_outDimTags_, &api_outDimTags_n_, (int)highestDimOnly, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         outDimTags.resize(api_outDimTags_n_ / 2); for(size_t i = 0; i < api_outDimTags_n_ / 2; ++i){ outDimTags[i].first = api_outDimTags_[i * 2 + 0]; outDimTags[i].second = api_outDimTags_[i * 2 + 1]; } gmshFree(api_outDimTags_);
       }
 
@@ -3795,7 +3806,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_dimTags_; size_t api_dimTags_n_;
         gmshModelOccGetEntities(&api_dimTags_, &api_dimTags_n_, dim, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         dimTags.resize(api_dimTags_n_ / 2); for(size_t i = 0; i < api_dimTags_n_ / 2; ++i){ dimTags[i].first = api_dimTags_[i * 2 + 0]; dimTags[i].second = api_dimTags_[i * 2 + 1]; } gmshFree(api_dimTags_);
       }
 
@@ -3815,7 +3826,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         int *api_tags_; size_t api_tags_n_;
         gmshModelOccGetEntitiesInBoundingBox(xmin, ymin, zmin, xmax, ymax, zmax, &api_tags_, &api_tags_n_, dim, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         tags.resize(api_tags_n_ / 2); for(size_t i = 0; i < api_tags_n_ / 2; ++i){ tags[i].first = api_tags_[i * 2 + 0]; tags[i].second = api_tags_[i * 2 + 1]; } gmshFree(api_tags_);
       }
 
@@ -3832,7 +3843,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         gmshModelOccGetBoundingBox(dim, tag, &xmin, &ymin, &zmin, &xmax, &ymax, &zmax, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
       }
 
       // Get the mass of the OpenCASCADE entity of dimension `dim' and tag `tag'.
@@ -3842,7 +3853,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         gmshModelOccGetMass(dim, tag, &mass, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
       }
 
       // Get the center of mass of the OpenCASCADE entity of dimension `dim' and
@@ -3855,7 +3866,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         gmshModelOccGetCenterOfMass(dim, tag, &x, &y, &z, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
       }
 
       // Get the matrix of inertia (by row) of the OpenCASCADE entity of dimension
@@ -3867,7 +3878,7 @@ namespace gmsh { // Top-level functions
         int ierr = 0;
         double *api_mat_; size_t api_mat_n_;
         gmshModelOccGetMatrixOfInertia(dim, tag, &api_mat_, &api_mat_n_, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         mat.assign(api_mat_, api_mat_ + api_mat_n_); gmshFree(api_mat_);
       }
 
@@ -3877,7 +3888,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         int result_api_ = gmshModelOccGetMaxTag(dim, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
         return result_api_;
       }
 
@@ -3888,7 +3899,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         gmshModelOccSetMaxTag(dim, maxTag, &ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
       }
 
       // Synchronize the OpenCASCADE CAD representation with the current Gmsh
@@ -3899,7 +3910,7 @@ namespace gmsh { // Top-level functions
       {
         int ierr = 0;
         gmshModelOccSynchronize(&ierr);
-        if(ierr) throw ierr;
+        if(ierr) throwLastError();
       }
 
       namespace mesh { // OpenCASCADE CAD kernel meshing constraints
@@ -3912,7 +3923,7 @@ namespace gmsh { // Top-level functions
           int ierr = 0;
           int *api_dimTags_; size_t api_dimTags_n_; vectorpair2intptr(dimTags, &api_dimTags_, &api_dimTags_n_);
           gmshModelOccMeshSetSize(api_dimTags_, api_dimTags_n_, size, &ierr);
-          if(ierr) throw ierr;
+          if(ierr) throwLastError();
           gmshFree(api_dimTags_);
         }
 
@@ -3932,7 +3943,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       int result_api_ = gmshViewAdd(name.c_str(), tag, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       return result_api_;
     }
 
@@ -3941,7 +3952,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       gmshViewRemove(tag, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
     }
 
     // Get the index of the view with tag `tag' in the list of currently loaded
@@ -3951,7 +3962,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       int result_api_ = gmshViewGetIndex(tag, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       return result_api_;
     }
 
@@ -3961,7 +3972,7 @@ namespace gmsh { // Top-level functions
       int ierr = 0;
       int *api_tags_; size_t api_tags_n_;
       gmshViewGetTags(&api_tags_, &api_tags_n_, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       tags.assign(api_tags_, api_tags_ + api_tags_n_); gmshFree(api_tags_);
     }
 
@@ -3991,7 +4002,7 @@ namespace gmsh { // Top-level functions
       size_t *api_tags_; size_t api_tags_n_; vector2ptr(tags, &api_tags_, &api_tags_n_);
       double **api_data_; size_t *api_data_n_, api_data_nn_; vectorvector2ptrptr(data, &api_data_, &api_data_n_, &api_data_nn_);
       gmshViewAddModelData(tag, step, modelName.c_str(), dataType.c_str(), api_tags_, api_tags_n_, (const double **)api_data_, api_data_n_, api_data_nn_, time, numComponents, partition, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       gmshFree(api_tags_);
       for(size_t i = 0; i < api_data_nn_; ++i){ gmshFree(api_data_[i]); } gmshFree(api_data_); gmshFree(api_data_n_);
     }
@@ -4015,7 +4026,7 @@ namespace gmsh { // Top-level functions
       size_t *api_tags_; size_t api_tags_n_; vector2ptr(tags, &api_tags_, &api_tags_n_);
       double *api_data_; size_t api_data_n_; vector2ptr(data, &api_data_, &api_data_n_);
       gmshViewAddHomogeneousModelData(tag, step, modelName.c_str(), dataType.c_str(), api_tags_, api_tags_n_, api_data_, api_data_n_, time, numComponents, partition, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       gmshFree(api_tags_);
       gmshFree(api_data_);
     }
@@ -4037,7 +4048,7 @@ namespace gmsh { // Top-level functions
       size_t *api_tags_; size_t api_tags_n_;
       double **api_data_; size_t *api_data_n_, api_data_nn_;
       gmshViewGetModelData(tag, step, &api_dataType_, &api_tags_, &api_tags_n_, &api_data_, &api_data_n_, &api_data_nn_, &time, &numComponents, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       dataType = std::string(api_dataType_); gmshFree(api_dataType_);
       tags.assign(api_tags_, api_tags_ + api_tags_n_); gmshFree(api_tags_);
       data.resize(api_data_nn_); for(size_t i = 0; i < api_data_nn_; ++i){ data[i].assign(api_data_[i], api_data_[i] + api_data_n_[i]); gmshFree(api_data_[i]); } gmshFree(api_data_); gmshFree(api_data_n_);
@@ -4060,7 +4071,7 @@ namespace gmsh { // Top-level functions
       size_t *api_tags_; size_t api_tags_n_;
       double *api_data_; size_t api_data_n_;
       gmshViewGetHomogeneousModelData(tag, step, &api_dataType_, &api_tags_, &api_tags_n_, &api_data_, &api_data_n_, &time, &numComponents, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       dataType = std::string(api_dataType_); gmshFree(api_dataType_);
       tags.assign(api_tags_, api_tags_ + api_tags_n_); gmshFree(api_tags_);
       data.assign(api_data_, api_data_ + api_data_n_); gmshFree(api_data_);
@@ -4078,7 +4089,7 @@ namespace gmsh { // Top-level functions
       int ierr = 0;
       double *api_data_; size_t api_data_n_; vector2ptr(data, &api_data_, &api_data_n_);
       gmshViewAddListData(tag, dataType.c_str(), numEle, api_data_, api_data_n_, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       gmshFree(api_data_);
     }
 
@@ -4095,7 +4106,7 @@ namespace gmsh { // Top-level functions
       int *api_numElements_; size_t api_numElements_n_;
       double **api_data_; size_t *api_data_n_, api_data_nn_;
       gmshViewGetListData(tag, &api_dataType_, &api_dataType_n_, &api_numElements_, &api_numElements_n_, &api_data_, &api_data_n_, &api_data_nn_, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       dataType.resize(api_dataType_n_); for(size_t i = 0; i < api_dataType_n_; ++i){ dataType[i] = std::string(api_dataType_[i]); gmshFree(api_dataType_[i]); } gmshFree(api_dataType_);
       numElements.assign(api_numElements_, api_numElements_ + api_numElements_n_); gmshFree(api_numElements_);
       data.resize(api_data_nn_); for(size_t i = 0; i < api_data_nn_; ++i){ data[i].assign(api_data_[i], api_data_[i] + api_data_n_[i]); gmshFree(api_data_[i]); } gmshFree(api_data_); gmshFree(api_data_n_);
@@ -4116,7 +4127,7 @@ namespace gmsh { // Top-level functions
       char **api_data_; size_t api_data_n_; vectorstring2charptrptr(data, &api_data_, &api_data_n_);
       char **api_style_; size_t api_style_n_; vectorstring2charptrptr(style, &api_style_, &api_style_n_);
       gmshViewAddListDataString(tag, api_coord_, api_coord_n_, api_data_, api_data_n_, api_style_, api_style_n_, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       gmshFree(api_coord_);
       for(size_t i = 0; i < api_data_n_; ++i){ gmshFree(api_data_[i]); } gmshFree(api_data_);
       for(size_t i = 0; i < api_style_n_; ++i){ gmshFree(api_style_[i]); } gmshFree(api_style_);
@@ -4136,7 +4147,7 @@ namespace gmsh { // Top-level functions
       char **api_data_; size_t api_data_n_;
       char **api_style_; size_t api_style_n_;
       gmshViewGetListDataStrings(tag, dim, &api_coord_, &api_coord_n_, &api_data_, &api_data_n_, &api_style_, &api_style_n_, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       coord.assign(api_coord_, api_coord_ + api_coord_n_); gmshFree(api_coord_);
       data.resize(api_data_n_); for(size_t i = 0; i < api_data_n_; ++i){ data[i] = std::string(api_data_[i]); gmshFree(api_data_[i]); } gmshFree(api_data_);
       style.resize(api_style_n_); for(size_t i = 0; i < api_style_n_; ++i){ style[i] = std::string(api_style_[i]); gmshFree(api_style_[i]); } gmshFree(api_style_);
@@ -4152,7 +4163,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       int result_api_ = gmshViewAddAlias(refTag, (int)copyOptions, tag, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       return result_api_;
     }
 
@@ -4162,7 +4173,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       gmshViewCopyOptions(refTag, tag, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
     }
 
     // Combine elements (if `what' == "elements") or steps (if `what' == "steps")
@@ -4176,7 +4187,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       gmshViewCombine(what.c_str(), how.c_str(), (int)remove, (int)copyOptions, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
     }
 
     // Probe the view `tag' for its `value' at point (`x', `y', `z'). Return only
@@ -4205,7 +4216,7 @@ namespace gmsh { // Top-level functions
       double *api_yElemCoord_; size_t api_yElemCoord_n_; vector2ptr(yElemCoord, &api_yElemCoord_, &api_yElemCoord_n_);
       double *api_zElemCoord_; size_t api_zElemCoord_n_; vector2ptr(zElemCoord, &api_zElemCoord_, &api_zElemCoord_n_);
       gmshViewProbe(tag, x, y, z, &api_value_, &api_value_n_, step, numComp, (int)gradient, tolerance, api_xElemCoord_, api_xElemCoord_n_, api_yElemCoord_, api_yElemCoord_n_, api_zElemCoord_, api_zElemCoord_n_, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       value.assign(api_value_, api_value_ + api_value_n_); gmshFree(api_value_);
       gmshFree(api_xElemCoord_);
       gmshFree(api_yElemCoord_);
@@ -4220,7 +4231,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       gmshViewWrite(tag, fileName.c_str(), (int)append, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
     }
 
   } // namespace view
@@ -4234,7 +4245,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       gmshPluginSetNumber(name.c_str(), option.c_str(), value, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
     }
 
     // Set the string option `option' to the value `value' for plugin `name'.
@@ -4244,7 +4255,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       gmshPluginSetString(name.c_str(), option.c_str(), value.c_str(), &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
     }
 
     // Run the plugin `name'.
@@ -4252,7 +4263,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       gmshPluginRun(name.c_str(), &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
     }
 
   } // namespace plugin
@@ -4264,7 +4275,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       gmshGraphicsDraw(&ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
     }
 
   } // namespace graphics
@@ -4277,7 +4288,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       gmshFltkInitialize(&ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
     }
 
     // Wait at most `time' seconds for user interface events and return. If `time'
@@ -4287,7 +4298,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       gmshFltkWait(time, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
     }
 
     // Update the user interface (potentially creating new widgets and windows).
@@ -4298,7 +4309,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       gmshFltkUpdate(&ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
     }
 
     // Awake the main user interface thread and process pending events, and
@@ -4308,7 +4319,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       gmshFltkAwake(action.c_str(), &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
     }
 
     // Block the current thread until it can safely modify the user interface.
@@ -4316,7 +4327,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       gmshFltkLock(&ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
     }
 
     // Release the lock that was set using lock.
@@ -4324,7 +4335,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       gmshFltkUnlock(&ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
     }
 
     // Run the event loop of the graphical user interface, i.e. repeatedly call
@@ -4334,7 +4345,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       gmshFltkRun(&ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
     }
 
     // Check if the user interface is available (e.g. to detect if it has been
@@ -4343,7 +4354,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       int result_api_ = gmshFltkIsAvailable(&ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       return result_api_;
     }
 
@@ -4355,7 +4366,7 @@ namespace gmsh { // Top-level functions
       int ierr = 0;
       int *api_dimTags_; size_t api_dimTags_n_;
       int result_api_ = gmshFltkSelectEntities(&api_dimTags_, &api_dimTags_n_, dim, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       dimTags.resize(api_dimTags_n_ / 2); for(size_t i = 0; i < api_dimTags_n_ / 2; ++i){ dimTags[i].first = api_dimTags_[i * 2 + 0]; dimTags[i].second = api_dimTags_[i * 2 + 1]; } gmshFree(api_dimTags_);
       return result_api_;
     }
@@ -4366,7 +4377,7 @@ namespace gmsh { // Top-level functions
       int ierr = 0;
       size_t *api_elementTags_; size_t api_elementTags_n_;
       int result_api_ = gmshFltkSelectElements(&api_elementTags_, &api_elementTags_n_, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       elementTags.assign(api_elementTags_, api_elementTags_ + api_elementTags_n_); gmshFree(api_elementTags_);
       return result_api_;
     }
@@ -4377,7 +4388,7 @@ namespace gmsh { // Top-level functions
       int ierr = 0;
       int *api_viewTags_; size_t api_viewTags_n_;
       int result_api_ = gmshFltkSelectViews(&api_viewTags_, &api_viewTags_n_, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       viewTags.assign(api_viewTags_, api_viewTags_ + api_viewTags_n_); gmshFree(api_viewTags_);
       return result_api_;
     }
@@ -4392,7 +4403,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       gmshOnelabSet(data.c_str(), format.c_str(), &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
     }
 
     // Get all the parameters (or a single one if `name' is specified) from the
@@ -4404,7 +4415,7 @@ namespace gmsh { // Top-level functions
       int ierr = 0;
       char *api_data_;
       gmshOnelabGet(&api_data_, name.c_str(), format.c_str(), &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       data = std::string(api_data_); gmshFree(api_data_);
     }
 
@@ -4417,7 +4428,7 @@ namespace gmsh { // Top-level functions
       int ierr = 0;
       double *api_value_; size_t api_value_n_; vector2ptr(value, &api_value_, &api_value_n_);
       gmshOnelabSetNumber(name.c_str(), api_value_, api_value_n_, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       gmshFree(api_value_);
     }
 
@@ -4430,7 +4441,7 @@ namespace gmsh { // Top-level functions
       int ierr = 0;
       char **api_value_; size_t api_value_n_; vectorstring2charptrptr(value, &api_value_, &api_value_n_);
       gmshOnelabSetString(name.c_str(), api_value_, api_value_n_, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       for(size_t i = 0; i < api_value_n_; ++i){ gmshFree(api_value_[i]); } gmshFree(api_value_);
     }
 
@@ -4442,7 +4453,7 @@ namespace gmsh { // Top-level functions
       int ierr = 0;
       double *api_value_; size_t api_value_n_;
       gmshOnelabGetNumber(name.c_str(), &api_value_, &api_value_n_, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       value.assign(api_value_, api_value_ + api_value_n_); gmshFree(api_value_);
     }
 
@@ -4454,7 +4465,7 @@ namespace gmsh { // Top-level functions
       int ierr = 0;
       char **api_value_; size_t api_value_n_;
       gmshOnelabGetString(name.c_str(), &api_value_, &api_value_n_, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       value.resize(api_value_n_); for(size_t i = 0; i < api_value_n_; ++i){ value[i] = std::string(api_value_[i]); gmshFree(api_value_[i]); } gmshFree(api_value_);
     }
 
@@ -4463,7 +4474,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       gmshOnelabClear(name.c_str(), &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
     }
 
     // Run a ONELAB client. If `name' is provided, create a new ONELAB client with
@@ -4474,7 +4485,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       gmshOnelabRun(name.c_str(), command.c_str(), &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
     }
 
   } // namespace onelab
@@ -4487,7 +4498,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       gmshLoggerWrite(message.c_str(), level.c_str(), &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
     }
 
     // Start logging messages.
@@ -4495,7 +4506,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       gmshLoggerStart(&ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
     }
 
     // Get logged messages.
@@ -4504,7 +4515,7 @@ namespace gmsh { // Top-level functions
       int ierr = 0;
       char **api_log_; size_t api_log_n_;
       gmshLoggerGet(&api_log_, &api_log_n_, &ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       log.resize(api_log_n_); for(size_t i = 0; i < api_log_n_; ++i){ log[i] = std::string(api_log_[i]); gmshFree(api_log_[i]); } gmshFree(api_log_);
     }
 
@@ -4513,7 +4524,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       gmshLoggerStop(&ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
     }
 
     // Return wall clock time.
@@ -4521,7 +4532,7 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       double result_api_ = gmshLoggerGetWallTime(&ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       return result_api_;
     }
 
@@ -4530,10 +4541,20 @@ namespace gmsh { // Top-level functions
     {
       int ierr = 0;
       double result_api_ = gmshLoggerGetCpuTime(&ierr);
-      if(ierr) throw ierr;
+      if(ierr) throwLastError();
       return result_api_;
     }
 
+    // Return last error message, if any.
+    inline void getLastError(std::string & error)
+    {
+      int ierr = 0;
+      char *api_error_;
+      gmshLoggerGetLastError(&api_error_, &ierr);
+      if(ierr) throw "Could not get last error";
+      error = std::string(api_error_); gmshFree(api_error_);
+    }
+
   } // namespace logger
 
 } // namespace gmsh
diff --git a/api/gmsh.jl b/api/gmsh.jl
index f6c76a4b9a..96a2ded275 100644
--- a/api/gmsh.jl
+++ b/api/gmsh.jl
@@ -39,7 +39,7 @@ function initialize(argv = Vector{String}(), readConfigFiles = true)
     ccall((:gmshInitialize, lib), Cvoid,
           (Cint, Ptr{Ptr{Cchar}}, Cint, Ptr{Cint}),
           length(argv), argv, readConfigFiles, ierr)
-    ierr[] != 0 && error("gmshInitialize returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -53,7 +53,7 @@ function finalize()
     ccall((:gmshFinalize, lib), Cvoid,
           (Ptr{Cint},),
           ierr)
-    ierr[] != 0 && error("gmshFinalize returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -69,7 +69,7 @@ function open(fileName)
     ccall((:gmshOpen, lib), Cvoid,
           (Ptr{Cchar}, Ptr{Cint}),
           fileName, ierr)
-    ierr[] != 0 && error("gmshOpen returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -85,7 +85,7 @@ function merge(fileName)
     ccall((:gmshMerge, lib), Cvoid,
           (Ptr{Cchar}, Ptr{Cint}),
           fileName, ierr)
-    ierr[] != 0 && error("gmshMerge returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -99,7 +99,7 @@ function write(fileName)
     ccall((:gmshWrite, lib), Cvoid,
           (Ptr{Cchar}, Ptr{Cint}),
           fileName, ierr)
-    ierr[] != 0 && error("gmshWrite returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -113,7 +113,7 @@ function clear()
     ccall((:gmshClear, lib), Cvoid,
           (Ptr{Cint},),
           ierr)
-    ierr[] != 0 && error("gmshClear returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -138,7 +138,7 @@ function setNumber(name, value)
     ccall((:gmshOptionSetNumber, gmsh.lib), Cvoid,
           (Ptr{Cchar}, Cdouble, Ptr{Cint}),
           name, value, ierr)
-    ierr[] != 0 && error("gmshOptionSetNumber returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -157,7 +157,7 @@ function getNumber(name)
     ccall((:gmshOptionGetNumber, gmsh.lib), Cvoid,
           (Ptr{Cchar}, Ptr{Cdouble}, Ptr{Cint}),
           name, api_value_, ierr)
-    ierr[] != 0 && error("gmshOptionGetNumber returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return api_value_[]
 end
 
@@ -173,7 +173,7 @@ function setString(name, value)
     ccall((:gmshOptionSetString, gmsh.lib), Cvoid,
           (Ptr{Cchar}, Ptr{Cchar}, Ptr{Cint}),
           name, value, ierr)
-    ierr[] != 0 && error("gmshOptionSetString returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -192,7 +192,7 @@ function getString(name)
     ccall((:gmshOptionGetString, gmsh.lib), Cvoid,
           (Ptr{Cchar}, Ptr{Ptr{Cchar}}, Ptr{Cint}),
           name, api_value_, ierr)
-    ierr[] != 0 && error("gmshOptionGetString returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     value = unsafe_string(api_value_[])
     return value
 end
@@ -211,7 +211,7 @@ function setColor(name, r, g, b, a = 255)
     ccall((:gmshOptionSetColor, gmsh.lib), Cvoid,
           (Ptr{Cchar}, Cint, Cint, Cint, Cint, Ptr{Cint}),
           name, r, g, b, a, ierr)
-    ierr[] != 0 && error("gmshOptionSetColor returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -234,7 +234,7 @@ function getColor(name)
     ccall((:gmshOptionGetColor, gmsh.lib), Cvoid,
           (Ptr{Cchar}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}),
           name, api_r_, api_g_, api_b_, api_a_, ierr)
-    ierr[] != 0 && error("gmshOptionGetColor returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return api_r_[], api_g_[], api_b_[], api_a_[]
 end
 
@@ -259,7 +259,7 @@ function add(name)
     ccall((:gmshModelAdd, gmsh.lib), Cvoid,
           (Ptr{Cchar}, Ptr{Cint}),
           name, ierr)
-    ierr[] != 0 && error("gmshModelAdd returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -273,7 +273,7 @@ function remove()
     ccall((:gmshModelRemove, gmsh.lib), Cvoid,
           (Ptr{Cint},),
           ierr)
-    ierr[] != 0 && error("gmshModelRemove returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -291,7 +291,7 @@ function list()
     ccall((:gmshModelList, gmsh.lib), Cvoid,
           (Ptr{Ptr{Ptr{Cchar}}}, Ptr{Csize_t}, Ptr{Cint}),
           api_names_, api_names_n_, ierr)
-    ierr[] != 0 && error("gmshModelList returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     tmp_api_names_ = unsafe_wrap(Array, api_names_[], api_names_n_[], own=true)
     names = [unsafe_string(tmp_api_names_[i]) for i in 1:length(tmp_api_names_) ]
     return names
@@ -310,7 +310,7 @@ function getCurrent()
     ccall((:gmshModelGetCurrent, gmsh.lib), Cvoid,
           (Ptr{Ptr{Cchar}}, Ptr{Cint}),
           api_name_, ierr)
-    ierr[] != 0 && error("gmshModelGetCurrent returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     name = unsafe_string(api_name_[])
     return name
 end
@@ -326,7 +326,7 @@ function setCurrent(name)
     ccall((:gmshModelSetCurrent, gmsh.lib), Cvoid,
           (Ptr{Cchar}, Ptr{Cint}),
           name, ierr)
-    ierr[] != 0 && error("gmshModelSetCurrent returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -346,7 +346,7 @@ function getEntities(dim = -1)
     ccall((:gmshModelGetEntities, gmsh.lib), Cvoid,
           (Ptr{Ptr{Cint}}, Ptr{Csize_t}, Cint, Ptr{Cint}),
           api_dimTags_, api_dimTags_n_, dim, ierr)
-    ierr[] != 0 && error("gmshModelGetEntities returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     tmp_api_dimTags_ = unsafe_wrap(Array, api_dimTags_[], api_dimTags_n_[], own=true)
     dimTags = [ (tmp_api_dimTags_[i], tmp_api_dimTags_[i+1]) for i in 1:2:length(tmp_api_dimTags_) ]
     return dimTags
@@ -362,7 +362,7 @@ function setEntityName(dim, tag, name)
     ccall((:gmshModelSetEntityName, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Cchar}, Ptr{Cint}),
           dim, tag, name, ierr)
-    ierr[] != 0 && error("gmshModelSetEntityName returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -379,7 +379,7 @@ function getEntityName(dim, tag)
     ccall((:gmshModelGetEntityName, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Ptr{Cchar}}, Ptr{Cint}),
           dim, tag, api_name_, ierr)
-    ierr[] != 0 && error("gmshModelGetEntityName returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     name = unsafe_string(api_name_[])
     return name
 end
@@ -400,7 +400,7 @@ function getPhysicalGroups(dim = -1)
     ccall((:gmshModelGetPhysicalGroups, gmsh.lib), Cvoid,
           (Ptr{Ptr{Cint}}, Ptr{Csize_t}, Cint, Ptr{Cint}),
           api_dimTags_, api_dimTags_n_, dim, ierr)
-    ierr[] != 0 && error("gmshModelGetPhysicalGroups returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     tmp_api_dimTags_ = unsafe_wrap(Array, api_dimTags_[], api_dimTags_n_[], own=true)
     dimTags = [ (tmp_api_dimTags_[i], tmp_api_dimTags_[i+1]) for i in 1:2:length(tmp_api_dimTags_) ]
     return dimTags
@@ -421,7 +421,7 @@ function getEntitiesForPhysicalGroup(dim, tag)
     ccall((:gmshModelGetEntitiesForPhysicalGroup, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Ptr{Cint}}, Ptr{Csize_t}, Ptr{Cint}),
           dim, tag, api_tags_, api_tags_n_, ierr)
-    ierr[] != 0 && error("gmshModelGetEntitiesForPhysicalGroup returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     tags = unsafe_wrap(Array, api_tags_[], api_tags_n_[], own=true)
     return tags
 end
@@ -441,7 +441,7 @@ function getPhysicalGroupsForEntity(dim, tag)
     ccall((:gmshModelGetPhysicalGroupsForEntity, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Ptr{Cint}}, Ptr{Csize_t}, Ptr{Cint}),
           dim, tag, api_physicalTags_, api_physicalTags_n_, ierr)
-    ierr[] != 0 && error("gmshModelGetPhysicalGroupsForEntity returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     physicalTags = unsafe_wrap(Array, api_physicalTags_[], api_physicalTags_n_[], own=true)
     return physicalTags
 end
@@ -457,11 +457,11 @@ Return an integer value.
 """
 function addPhysicalGroup(dim, tags, tag = -1)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelAddPhysicalGroup, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelAddPhysicalGroup, gmsh.lib), Cint,
           (Cint, Ptr{Cint}, Csize_t, Cint, Ptr{Cint}),
           dim, convert(Vector{Cint}, tags), length(tags), tag, ierr)
-    ierr[] != 0 && error("gmshModelAddPhysicalGroup returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -474,7 +474,7 @@ function setPhysicalName(dim, tag, name)
     ccall((:gmshModelSetPhysicalName, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Cchar}, Ptr{Cint}),
           dim, tag, name, ierr)
-    ierr[] != 0 && error("gmshModelSetPhysicalName returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -491,7 +491,7 @@ function getPhysicalName(dim, tag)
     ccall((:gmshModelGetPhysicalName, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Ptr{Cchar}}, Ptr{Cint}),
           dim, tag, api_name_, ierr)
-    ierr[] != 0 && error("gmshModelGetPhysicalName returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     name = unsafe_string(api_name_[])
     return name
 end
@@ -517,7 +517,7 @@ function getBoundary(dimTags, combined = true, oriented = true, recursive = fals
     ccall((:gmshModelGetBoundary, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Ptr{Ptr{Cint}}, Ptr{Csize_t}, Cint, Cint, Cint, Ptr{Cint}),
           api_dimTags_, api_dimTags_n_, api_outDimTags_, api_outDimTags_n_, combined, oriented, recursive, ierr)
-    ierr[] != 0 && error("gmshModelGetBoundary returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     tmp_api_outDimTags_ = unsafe_wrap(Array, api_outDimTags_[], api_outDimTags_n_[], own=true)
     outDimTags = [ (tmp_api_outDimTags_[i], tmp_api_outDimTags_[i+1]) for i in 1:2:length(tmp_api_outDimTags_) ]
     return outDimTags
@@ -539,7 +539,7 @@ function getEntitiesInBoundingBox(xmin, ymin, zmin, xmax, ymax, zmax, dim = -1)
     ccall((:gmshModelGetEntitiesInBoundingBox, gmsh.lib), Cvoid,
           (Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Ptr{Ptr{Cint}}, Ptr{Csize_t}, Cint, Ptr{Cint}),
           xmin, ymin, zmin, xmax, ymax, zmax, api_tags_, api_tags_n_, dim, ierr)
-    ierr[] != 0 && error("gmshModelGetEntitiesInBoundingBox returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     tmp_api_tags_ = unsafe_wrap(Array, api_tags_[], api_tags_n_[], own=true)
     tags = [ (tmp_api_tags_[i], tmp_api_tags_[i+1]) for i in 1:2:length(tmp_api_tags_) ]
     return tags
@@ -565,7 +565,7 @@ function getBoundingBox(dim, tag)
     ccall((:gmshModelGetBoundingBox, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cint}),
           dim, tag, api_xmin_, api_ymin_, api_zmin_, api_xmax_, api_ymax_, api_zmax_, ierr)
-    ierr[] != 0 && error("gmshModelGetBoundingBox returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return api_xmin_[], api_ymin_[], api_zmin_[], api_xmax_[], api_ymax_[], api_zmax_[]
 end
 
@@ -578,11 +578,11 @@ Return an integer value.
 """
 function getDimension()
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelGetDimension, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelGetDimension, gmsh.lib), Cint,
           (Ptr{Cint},),
           ierr)
-    ierr[] != 0 && error("gmshModelGetDimension returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -598,11 +598,11 @@ Return an integer value.
 """
 function addDiscreteEntity(dim, tag = -1, boundary = Cint[])
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelAddDiscreteEntity, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelAddDiscreteEntity, gmsh.lib), Cint,
           (Cint, Cint, Ptr{Cint}, Csize_t, Ptr{Cint}),
           dim, tag, convert(Vector{Cint}, boundary), length(boundary), ierr)
-    ierr[] != 0 && error("gmshModelAddDiscreteEntity returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -618,7 +618,7 @@ function removeEntities(dimTags, recursive = false)
     ccall((:gmshModelRemoveEntities, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Cint, Ptr{Cint}),
           api_dimTags_, api_dimTags_n_, recursive, ierr)
-    ierr[] != 0 && error("gmshModelRemoveEntities returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -632,7 +632,7 @@ function removeEntityName(name)
     ccall((:gmshModelRemoveEntityName, gmsh.lib), Cvoid,
           (Ptr{Cchar}, Ptr{Cint}),
           name, ierr)
-    ierr[] != 0 && error("gmshModelRemoveEntityName returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -649,7 +649,7 @@ function removePhysicalGroups(dimTags = Tuple{Cint,Cint}[])
     ccall((:gmshModelRemovePhysicalGroups, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Ptr{Cint}),
           api_dimTags_, api_dimTags_n_, ierr)
-    ierr[] != 0 && error("gmshModelRemovePhysicalGroups returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -663,7 +663,7 @@ function removePhysicalName(name)
     ccall((:gmshModelRemovePhysicalName, gmsh.lib), Cvoid,
           (Ptr{Cchar}, Ptr{Cint}),
           name, ierr)
-    ierr[] != 0 && error("gmshModelRemovePhysicalName returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -680,7 +680,7 @@ function getType(dim, tag)
     ccall((:gmshModelGetType, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Ptr{Cchar}}, Ptr{Cint}),
           dim, tag, api_entityType_, ierr)
-    ierr[] != 0 && error("gmshModelGetType returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     entityType = unsafe_string(api_entityType_[])
     return entityType
 end
@@ -701,7 +701,7 @@ function getParent(dim, tag)
     ccall((:gmshModelGetParent, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}),
           dim, tag, api_parentDim_, api_parentTag_, ierr)
-    ierr[] != 0 && error("gmshModelGetParent returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return api_parentDim_[], api_parentTag_[]
 end
 
@@ -720,7 +720,7 @@ function getPartitions(dim, tag)
     ccall((:gmshModelGetPartitions, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Ptr{Cint}}, Ptr{Csize_t}, Ptr{Cint}),
           dim, tag, api_partitions_, api_partitions_n_, ierr)
-    ierr[] != 0 && error("gmshModelGetPartitions returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     partitions = unsafe_wrap(Array, api_partitions_[], api_partitions_n_[], own=true)
     return partitions
 end
@@ -745,7 +745,7 @@ function getValue(dim, tag, parametricCoord)
     ccall((:gmshModelGetValue, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Cdouble}, Csize_t, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Ptr{Cint}),
           dim, tag, convert(Vector{Cdouble}, parametricCoord), length(parametricCoord), api_coord_, api_coord_n_, ierr)
-    ierr[] != 0 && error("gmshModelGetValue returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     coord = unsafe_wrap(Array, api_coord_[], api_coord_n_[], own=true)
     return coord
 end
@@ -772,7 +772,7 @@ function getDerivative(dim, tag, parametricCoord)
     ccall((:gmshModelGetDerivative, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Cdouble}, Csize_t, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Ptr{Cint}),
           dim, tag, convert(Vector{Cdouble}, parametricCoord), length(parametricCoord), api_derivatives_, api_derivatives_n_, ierr)
-    ierr[] != 0 && error("gmshModelGetDerivative returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     derivatives = unsafe_wrap(Array, api_derivatives_[], api_derivatives_n_[], own=true)
     return derivatives
 end
@@ -795,7 +795,7 @@ function getCurvature(dim, tag, parametricCoord)
     ccall((:gmshModelGetCurvature, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Cdouble}, Csize_t, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Ptr{Cint}),
           dim, tag, convert(Vector{Cdouble}, parametricCoord), length(parametricCoord), api_curvatures_, api_curvatures_n_, ierr)
-    ierr[] != 0 && error("gmshModelGetCurvature returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     curvatures = unsafe_wrap(Array, api_curvatures_[], api_curvatures_n_[], own=true)
     return curvatures
 end
@@ -823,7 +823,7 @@ function getPrincipalCurvatures(tag, parametricCoord)
     ccall((:gmshModelGetPrincipalCurvatures, gmsh.lib), Cvoid,
           (Cint, Ptr{Cdouble}, Csize_t, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Ptr{Cint}),
           tag, convert(Vector{Cdouble}, parametricCoord), length(parametricCoord), api_curvatureMax_, api_curvatureMax_n_, api_curvatureMin_, api_curvatureMin_n_, api_directionMax_, api_directionMax_n_, api_directionMin_, api_directionMin_n_, ierr)
-    ierr[] != 0 && error("gmshModelGetPrincipalCurvatures returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     curvatureMax = unsafe_wrap(Array, api_curvatureMax_[], api_curvatureMax_n_[], own=true)
     curvatureMin = unsafe_wrap(Array, api_curvatureMin_[], api_curvatureMin_n_[], own=true)
     directionMax = unsafe_wrap(Array, api_directionMax_[], api_directionMax_n_[], own=true)
@@ -848,7 +848,7 @@ function getNormal(tag, parametricCoord)
     ccall((:gmshModelGetNormal, gmsh.lib), Cvoid,
           (Cint, Ptr{Cdouble}, Csize_t, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Ptr{Cint}),
           tag, convert(Vector{Cdouble}, parametricCoord), length(parametricCoord), api_normals_, api_normals_n_, ierr)
-    ierr[] != 0 && error("gmshModelGetNormal returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     normals = unsafe_wrap(Array, api_normals_[], api_normals_n_[], own=true)
     return normals
 end
@@ -872,7 +872,7 @@ function getParametrization(dim, tag, coord)
     ccall((:gmshModelGetParametrization, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Cdouble}, Csize_t, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Ptr{Cint}),
           dim, tag, convert(Vector{Cdouble}, coord), length(coord), api_parametricCoord_, api_parametricCoord_n_, ierr)
-    ierr[] != 0 && error("gmshModelGetParametrization returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     parametricCoord = unsafe_wrap(Array, api_parametricCoord_[], api_parametricCoord_n_[], own=true)
     return parametricCoord
 end
@@ -894,7 +894,7 @@ function getParametrizationBounds(dim, tag)
     ccall((:gmshModelGetParametrizationBounds, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Ptr{Cint}),
           dim, tag, api_min_, api_min_n_, api_max_, api_max_n_, ierr)
-    ierr[] != 0 && error("gmshModelGetParametrizationBounds returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     min = unsafe_wrap(Array, api_min_[], api_min_n_[], own=true)
     max = unsafe_wrap(Array, api_max_[], api_max_n_[], own=true)
     return min, max
@@ -912,11 +912,11 @@ Return an integer value.
 """
 function isInside(dim, tag, parametricCoord)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelIsInside, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelIsInside, gmsh.lib), Cint,
           (Cint, Cint, Ptr{Cdouble}, Csize_t, Ptr{Cint}),
           dim, tag, convert(Vector{Cdouble}, parametricCoord), length(parametricCoord), ierr)
-    ierr[] != 0 && error("gmshModelIsInside returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -940,7 +940,7 @@ function getClosestPoint(dim, tag, coord)
     ccall((:gmshModelGetClosestPoint, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Cdouble}, Csize_t, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Ptr{Cint}),
           dim, tag, convert(Vector{Cdouble}, coord), length(coord), api_closestCoord_, api_closestCoord_n_, api_parametricCoord_, api_parametricCoord_n_, ierr)
-    ierr[] != 0 && error("gmshModelGetClosestPoint returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     closestCoord = unsafe_wrap(Array, api_closestCoord_[], api_closestCoord_n_[], own=true)
     parametricCoord = unsafe_wrap(Array, api_parametricCoord_[], api_parametricCoord_n_[], own=true)
     return closestCoord, parametricCoord
@@ -965,7 +965,7 @@ function reparametrizeOnSurface(dim, tag, parametricCoord, surfaceTag, which = 0
     ccall((:gmshModelReparametrizeOnSurface, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Cdouble}, Csize_t, Cint, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Cint, Ptr{Cint}),
           dim, tag, convert(Vector{Cdouble}, parametricCoord), length(parametricCoord), surfaceTag, api_surfaceParametricCoord_, api_surfaceParametricCoord_n_, which, ierr)
-    ierr[] != 0 && error("gmshModelReparametrizeOnSurface returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     surfaceParametricCoord = unsafe_wrap(Array, api_surfaceParametricCoord_[], api_surfaceParametricCoord_n_[], own=true)
     return surfaceParametricCoord
 end
@@ -983,7 +983,7 @@ function setVisibility(dimTags, value, recursive = false)
     ccall((:gmshModelSetVisibility, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Cint, Cint, Ptr{Cint}),
           api_dimTags_, api_dimTags_n_, value, recursive, ierr)
-    ierr[] != 0 && error("gmshModelSetVisibility returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -1000,7 +1000,7 @@ function getVisibility(dim, tag)
     ccall((:gmshModelGetVisibility, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Cint}, Ptr{Cint}),
           dim, tag, api_value_, ierr)
-    ierr[] != 0 && error("gmshModelGetVisibility returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return api_value_[]
 end
 
@@ -1018,7 +1018,7 @@ function setColor(dimTags, r, g, b, a = 255, recursive = false)
     ccall((:gmshModelSetColor, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Cint, Cint, Cint, Cint, Cint, Ptr{Cint}),
           api_dimTags_, api_dimTags_n_, r, g, b, a, recursive, ierr)
-    ierr[] != 0 && error("gmshModelSetColor returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -1038,7 +1038,7 @@ function getColor(dim, tag)
     ccall((:gmshModelGetColor, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}),
           dim, tag, api_r_, api_g_, api_b_, api_a_, ierr)
-    ierr[] != 0 && error("gmshModelGetColor returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return api_r_[], api_g_[], api_b_[], api_a_[]
 end
 
@@ -1052,7 +1052,7 @@ function setCoordinates(tag, x, y, z)
     ccall((:gmshModelSetCoordinates, gmsh.lib), Cvoid,
           (Cint, Cdouble, Cdouble, Cdouble, Ptr{Cint}),
           tag, x, y, z, ierr)
-    ierr[] != 0 && error("gmshModelSetCoordinates returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -1075,7 +1075,7 @@ function generate(dim = 3)
     ccall((:gmshModelMeshGenerate, gmsh.lib), Cvoid,
           (Cint, Ptr{Cint}),
           dim, ierr)
-    ierr[] != 0 && error("gmshModelMeshGenerate returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -1089,7 +1089,7 @@ function partition(numPart)
     ccall((:gmshModelMeshPartition, gmsh.lib), Cvoid,
           (Cint, Ptr{Cint}),
           numPart, ierr)
-    ierr[] != 0 && error("gmshModelMeshPartition returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -1103,7 +1103,7 @@ function unpartition()
     ccall((:gmshModelMeshUnpartition, gmsh.lib), Cvoid,
           (Ptr{Cint},),
           ierr)
-    ierr[] != 0 && error("gmshModelMeshUnpartition returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -1125,7 +1125,7 @@ function optimize(method, force = false, niter = 1, dimTags = Tuple{Cint,Cint}[]
     ccall((:gmshModelMeshOptimize, gmsh.lib), Cvoid,
           (Ptr{Cchar}, Cint, Cint, Ptr{Cint}, Csize_t, Ptr{Cint}),
           method, force, niter, api_dimTags_, api_dimTags_n_, ierr)
-    ierr[] != 0 && error("gmshModelMeshOptimize returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -1139,7 +1139,7 @@ function recombine()
     ccall((:gmshModelMeshRecombine, gmsh.lib), Cvoid,
           (Ptr{Cint},),
           ierr)
-    ierr[] != 0 && error("gmshModelMeshRecombine returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -1153,7 +1153,7 @@ function refine()
     ccall((:gmshModelMeshRefine, gmsh.lib), Cvoid,
           (Ptr{Cint},),
           ierr)
-    ierr[] != 0 && error("gmshModelMeshRefine returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -1167,7 +1167,7 @@ function setOrder(order)
     ccall((:gmshModelMeshSetOrder, gmsh.lib), Cvoid,
           (Cint, Ptr{Cint}),
           order, ierr)
-    ierr[] != 0 && error("gmshModelMeshSetOrder returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -1186,7 +1186,7 @@ function getLastEntityError()
     ccall((:gmshModelMeshGetLastEntityError, gmsh.lib), Cvoid,
           (Ptr{Ptr{Cint}}, Ptr{Csize_t}, Ptr{Cint}),
           api_dimTags_, api_dimTags_n_, ierr)
-    ierr[] != 0 && error("gmshModelMeshGetLastEntityError returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     tmp_api_dimTags_ = unsafe_wrap(Array, api_dimTags_[], api_dimTags_n_[], own=true)
     dimTags = [ (tmp_api_dimTags_[i], tmp_api_dimTags_[i+1]) for i in 1:2:length(tmp_api_dimTags_) ]
     return dimTags
@@ -1207,7 +1207,7 @@ function getLastNodeError()
     ccall((:gmshModelMeshGetLastNodeError, gmsh.lib), Cvoid,
           (Ptr{Ptr{Csize_t}}, Ptr{Csize_t}, Ptr{Cint}),
           api_nodeTags_, api_nodeTags_n_, ierr)
-    ierr[] != 0 && error("gmshModelMeshGetLastNodeError returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     nodeTags = unsafe_wrap(Array, api_nodeTags_[], api_nodeTags_n_[], own=true)
     return nodeTags
 end
@@ -1227,7 +1227,7 @@ function clear(dimTags = Tuple{Cint,Cint}[])
     ccall((:gmshModelMeshClear, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Ptr{Cint}),
           api_dimTags_, api_dimTags_n_, ierr)
-    ierr[] != 0 && error("gmshModelMeshClear returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -1260,7 +1260,7 @@ function getNodes(dim = -1, tag = -1, includeBoundary = false, returnParametricC
     ccall((:gmshModelMeshGetNodes, gmsh.lib), Cvoid,
           (Ptr{Ptr{Csize_t}}, Ptr{Csize_t}, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Cint, Cint, Cint, Cint, Ptr{Cint}),
           api_nodeTags_, api_nodeTags_n_, api_coord_, api_coord_n_, api_parametricCoord_, api_parametricCoord_n_, dim, tag, includeBoundary, returnParametricCoord, ierr)
-    ierr[] != 0 && error("gmshModelMeshGetNodes returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     nodeTags = unsafe_wrap(Array, api_nodeTags_[], api_nodeTags_n_[], own=true)
     coord = unsafe_wrap(Array, api_coord_[], api_coord_n_[], own=true)
     parametricCoord = unsafe_wrap(Array, api_parametricCoord_[], api_parametricCoord_n_[], own=true)
@@ -1286,7 +1286,7 @@ function getNodesByElementType(elementType, tag = -1, returnParametricCoord = tr
     ccall((:gmshModelMeshGetNodesByElementType, gmsh.lib), Cvoid,
           (Cint, Ptr{Ptr{Csize_t}}, Ptr{Csize_t}, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Cint, Cint, Ptr{Cint}),
           elementType, api_nodeTags_, api_nodeTags_n_, api_coord_, api_coord_n_, api_parametricCoord_, api_parametricCoord_n_, tag, returnParametricCoord, ierr)
-    ierr[] != 0 && error("gmshModelMeshGetNodesByElementType returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     nodeTags = unsafe_wrap(Array, api_nodeTags_[], api_nodeTags_n_[], own=true)
     coord = unsafe_wrap(Array, api_coord_[], api_coord_n_[], own=true)
     parametricCoord = unsafe_wrap(Array, api_parametricCoord_[], api_parametricCoord_n_[], own=true)
@@ -1312,7 +1312,7 @@ function getNode(nodeTag)
     ccall((:gmshModelMeshGetNode, gmsh.lib), Cvoid,
           (Csize_t, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Ptr{Cint}),
           nodeTag, api_coord_, api_coord_n_, api_parametricCoord_, api_parametricCoord_n_, ierr)
-    ierr[] != 0 && error("gmshModelMeshGetNode returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     coord = unsafe_wrap(Array, api_coord_[], api_coord_n_[], own=true)
     parametricCoord = unsafe_wrap(Array, api_parametricCoord_[], api_parametricCoord_n_[], own=true)
     return coord, parametricCoord
@@ -1331,7 +1331,7 @@ function setNode(nodeTag, coord, parametricCoord)
     ccall((:gmshModelMeshSetNode, gmsh.lib), Cvoid,
           (Csize_t, Ptr{Cdouble}, Csize_t, Ptr{Cdouble}, Csize_t, Ptr{Cint}),
           nodeTag, convert(Vector{Cdouble}, coord), length(coord), convert(Vector{Cdouble}, parametricCoord), length(parametricCoord), ierr)
-    ierr[] != 0 && error("gmshModelMeshSetNode returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -1345,7 +1345,7 @@ function rebuildNodeCache(onlyIfNecessary = true)
     ccall((:gmshModelMeshRebuildNodeCache, gmsh.lib), Cvoid,
           (Cint, Ptr{Cint}),
           onlyIfNecessary, ierr)
-    ierr[] != 0 && error("gmshModelMeshRebuildNodeCache returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -1359,7 +1359,7 @@ function rebuildElementCache(onlyIfNecessary = true)
     ccall((:gmshModelMeshRebuildElementCache, gmsh.lib), Cvoid,
           (Cint, Ptr{Cint}),
           onlyIfNecessary, ierr)
-    ierr[] != 0 && error("gmshModelMeshRebuildElementCache returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -1382,7 +1382,7 @@ function getNodesForPhysicalGroup(dim, tag)
     ccall((:gmshModelMeshGetNodesForPhysicalGroup, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Ptr{Csize_t}}, Ptr{Csize_t}, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Ptr{Cint}),
           dim, tag, api_nodeTags_, api_nodeTags_n_, api_coord_, api_coord_n_, ierr)
-    ierr[] != 0 && error("gmshModelMeshGetNodesForPhysicalGroup returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     nodeTags = unsafe_wrap(Array, api_nodeTags_[], api_nodeTags_n_[], own=true)
     coord = unsafe_wrap(Array, api_coord_[], api_coord_n_[], own=true)
     return nodeTags, coord
@@ -1405,7 +1405,7 @@ function addNodes(dim, tag, nodeTags, coord, parametricCoord = Cdouble[])
     ccall((:gmshModelMeshAddNodes, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Csize_t}, Csize_t, Ptr{Cdouble}, Csize_t, Ptr{Cdouble}, Csize_t, Ptr{Cint}),
           dim, tag, convert(Vector{Csize_t}, nodeTags), length(nodeTags), convert(Vector{Cdouble}, coord), length(coord), convert(Vector{Cdouble}, parametricCoord), length(parametricCoord), ierr)
-    ierr[] != 0 && error("gmshModelMeshAddNodes returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -1422,7 +1422,7 @@ function reclassifyNodes()
     ccall((:gmshModelMeshReclassifyNodes, gmsh.lib), Cvoid,
           (Ptr{Cint},),
           ierr)
-    ierr[] != 0 && error("gmshModelMeshReclassifyNodes returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -1439,7 +1439,7 @@ function relocateNodes(dim = -1, tag = -1)
     ccall((:gmshModelMeshRelocateNodes, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Cint}),
           dim, tag, ierr)
-    ierr[] != 0 && error("gmshModelMeshRelocateNodes returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -1474,7 +1474,7 @@ function getElements(dim = -1, tag = -1)
     ccall((:gmshModelMeshGetElements, gmsh.lib), Cvoid,
           (Ptr{Ptr{Cint}}, Ptr{Csize_t}, Ptr{Ptr{Ptr{Csize_t}}}, Ptr{Ptr{Csize_t}}, Ptr{Csize_t}, Ptr{Ptr{Ptr{Csize_t}}}, Ptr{Ptr{Csize_t}}, Ptr{Csize_t}, Cint, Cint, Ptr{Cint}),
           api_elementTypes_, api_elementTypes_n_, api_elementTags_, api_elementTags_n_, api_elementTags_nn_, api_nodeTags_, api_nodeTags_n_, api_nodeTags_nn_, dim, tag, ierr)
-    ierr[] != 0 && error("gmshModelMeshGetElements returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     elementTypes = unsafe_wrap(Array, api_elementTypes_[], api_elementTypes_n_[], own=true)
     tmp_api_elementTags_ = unsafe_wrap(Array, api_elementTags_[], api_elementTags_nn_[], own=true)
     tmp_api_elementTags_n_ = unsafe_wrap(Array, api_elementTags_n_[], api_elementTags_nn_[], own=true)
@@ -1502,7 +1502,7 @@ function getElement(elementTag)
     ccall((:gmshModelMeshGetElement, gmsh.lib), Cvoid,
           (Csize_t, Ptr{Cint}, Ptr{Ptr{Csize_t}}, Ptr{Csize_t}, Ptr{Cint}),
           elementTag, api_elementType_, api_nodeTags_, api_nodeTags_n_, ierr)
-    ierr[] != 0 && error("gmshModelMeshGetElement returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     nodeTags = unsafe_wrap(Array, api_nodeTags_[], api_nodeTags_n_[], own=true)
     return api_elementType_[], nodeTags
 end
@@ -1531,7 +1531,7 @@ function getElementByCoordinates(x, y, z, dim = -1, strict = false)
     ccall((:gmshModelMeshGetElementByCoordinates, gmsh.lib), Cvoid,
           (Cdouble, Cdouble, Cdouble, Ptr{Csize_t}, Ptr{Cint}, Ptr{Ptr{Csize_t}}, Ptr{Csize_t}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}, Cint, Cint, Ptr{Cint}),
           x, y, z, api_elementTag_, api_elementType_, api_nodeTags_, api_nodeTags_n_, api_u_, api_v_, api_w_, dim, strict, ierr)
-    ierr[] != 0 && error("gmshModelMeshGetElementByCoordinates returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     nodeTags = unsafe_wrap(Array, api_nodeTags_[], api_nodeTags_n_[], own=true)
     return api_elementTag_[], api_elementType_[], nodeTags, api_u_[], api_v_[], api_w_[]
 end
@@ -1555,7 +1555,7 @@ function getElementsByCoordinates(x, y, z, dim = -1, strict = false)
     ccall((:gmshModelMeshGetElementsByCoordinates, gmsh.lib), Cvoid,
           (Cdouble, Cdouble, Cdouble, Ptr{Ptr{Csize_t}}, Ptr{Csize_t}, Cint, Cint, Ptr{Cint}),
           x, y, z, api_elementTags_, api_elementTags_n_, dim, strict, ierr)
-    ierr[] != 0 && error("gmshModelMeshGetElementsByCoordinates returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     elementTags = unsafe_wrap(Array, api_elementTags_[], api_elementTags_n_[], own=true)
     return elementTags
 end
@@ -1578,7 +1578,7 @@ function getLocalCoordinatesInElement(elementTag, x, y, z)
     ccall((:gmshModelMeshGetLocalCoordinatesInElement, gmsh.lib), Cvoid,
           (Csize_t, Cdouble, Cdouble, Cdouble, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cint}),
           elementTag, x, y, z, api_u_, api_v_, api_w_, ierr)
-    ierr[] != 0 && error("gmshModelMeshGetLocalCoordinatesInElement returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return api_u_[], api_v_[], api_w_[]
 end
 
@@ -1598,7 +1598,7 @@ function getElementTypes(dim = -1, tag = -1)
     ccall((:gmshModelMeshGetElementTypes, gmsh.lib), Cvoid,
           (Ptr{Ptr{Cint}}, Ptr{Csize_t}, Cint, Cint, Ptr{Cint}),
           api_elementTypes_, api_elementTypes_n_, dim, tag, ierr)
-    ierr[] != 0 && error("gmshModelMeshGetElementTypes returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     elementTypes = unsafe_wrap(Array, api_elementTypes_[], api_elementTypes_n_[], own=true)
     return elementTypes
 end
@@ -1615,11 +1615,11 @@ Return an integer value.
 """
 function getElementType(familyName, order, serendip = false)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelMeshGetElementType, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelMeshGetElementType, gmsh.lib), Cint,
           (Ptr{Cchar}, Cint, Cint, Ptr{Cint}),
           familyName, order, serendip, ierr)
-    ierr[] != 0 && error("gmshModelMeshGetElementType returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -1645,7 +1645,7 @@ function getElementProperties(elementType)
     ccall((:gmshModelMeshGetElementProperties, gmsh.lib), Cvoid,
           (Cint, Ptr{Ptr{Cchar}}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Ptr{Cint}, Ptr{Cint}),
           elementType, api_elementName_, api_dim_, api_order_, api_numNodes_, api_localNodeCoord_, api_localNodeCoord_n_, api_numPrimaryNodes_, ierr)
-    ierr[] != 0 && error("gmshModelMeshGetElementProperties returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     elementName = unsafe_string(api_elementName_[])
     localNodeCoord = unsafe_wrap(Array, api_localNodeCoord_[], api_localNodeCoord_n_[], own=true)
     return elementName, api_dim_[], api_order_[], api_numNodes_[], localNodeCoord, api_numPrimaryNodes_[]
@@ -1674,7 +1674,7 @@ function getElementsByType(elementType, tag = -1, task = 0, numTasks = 1)
     ccall((:gmshModelMeshGetElementsByType, gmsh.lib), Cvoid,
           (Cint, Ptr{Ptr{Csize_t}}, Ptr{Csize_t}, Ptr{Ptr{Csize_t}}, Ptr{Csize_t}, Cint, Csize_t, Csize_t, Ptr{Cint}),
           elementType, api_elementTags_, api_elementTags_n_, api_nodeTags_, api_nodeTags_n_, tag, task, numTasks, ierr)
-    ierr[] != 0 && error("gmshModelMeshGetElementsByType returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     elementTags = unsafe_wrap(Array, api_elementTags_[], api_elementTags_n_[], own=true)
     nodeTags = unsafe_wrap(Array, api_nodeTags_[], api_nodeTags_n_[], own=true)
     return elementTags, nodeTags
@@ -1700,7 +1700,7 @@ function addElements(dim, tag, elementTypes, elementTags, nodeTags)
     ccall((:gmshModelMeshAddElements, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Cint}, Csize_t, Ptr{Ptr{Csize_t}}, Ptr{Csize_t}, Csize_t, Ptr{Ptr{Csize_t}}, Ptr{Csize_t}, Csize_t, Ptr{Cint}),
           dim, tag, convert(Vector{Cint}, elementTypes), length(elementTypes), convert(Vector{Vector{Csize_t}},elementTags), api_elementTags_n_, length(elementTags), convert(Vector{Vector{Csize_t}},nodeTags), api_nodeTags_n_, length(nodeTags), ierr)
-    ierr[] != 0 && error("gmshModelMeshAddElements returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -1720,7 +1720,7 @@ function addElementsByType(tag, elementType, elementTags, nodeTags)
     ccall((:gmshModelMeshAddElementsByType, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Csize_t}, Csize_t, Ptr{Csize_t}, Csize_t, Ptr{Cint}),
           tag, elementType, convert(Vector{Csize_t}, elementTags), length(elementTags), convert(Vector{Csize_t}, nodeTags), length(nodeTags), ierr)
-    ierr[] != 0 && error("gmshModelMeshAddElementsByType returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -1745,7 +1745,7 @@ function getIntegrationPoints(elementType, integrationType)
     ccall((:gmshModelMeshGetIntegrationPoints, gmsh.lib), Cvoid,
           (Cint, Ptr{Cchar}, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Ptr{Cint}),
           elementType, integrationType, api_localCoord_, api_localCoord_n_, api_weights_, api_weights_n_, ierr)
-    ierr[] != 0 && error("gmshModelMeshGetIntegrationPoints returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     localCoord = unsafe_wrap(Array, api_localCoord_[], api_localCoord_n_[], own=true)
     weights = unsafe_wrap(Array, api_weights_[], api_weights_n_[], own=true)
     return localCoord, weights
@@ -1781,7 +1781,7 @@ function getJacobians(elementType, localCoord, tag = -1, task = 0, numTasks = 1)
     ccall((:gmshModelMeshGetJacobians, gmsh.lib), Cvoid,
           (Cint, Ptr{Cdouble}, Csize_t, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Cint, Csize_t, Csize_t, Ptr{Cint}),
           elementType, convert(Vector{Cdouble}, localCoord), length(localCoord), api_jacobians_, api_jacobians_n_, api_determinants_, api_determinants_n_, api_coord_, api_coord_n_, tag, task, numTasks, ierr)
-    ierr[] != 0 && error("gmshModelMeshGetJacobians returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     jacobians = unsafe_wrap(Array, api_jacobians_[], api_jacobians_n_[], own=true)
     determinants = unsafe_wrap(Array, api_determinants_[], api_determinants_n_[], own=true)
     coord = unsafe_wrap(Array, api_coord_[], api_coord_n_[], own=true)
@@ -1815,7 +1815,7 @@ function getJacobian(elementTag, localCoord)
     ccall((:gmshModelMeshGetJacobian, gmsh.lib), Cvoid,
           (Csize_t, Ptr{Cdouble}, Csize_t, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Ptr{Cint}),
           elementTag, convert(Vector{Cdouble}, localCoord), length(localCoord), api_jacobians_, api_jacobians_n_, api_determinants_, api_determinants_n_, api_coord_, api_coord_n_, ierr)
-    ierr[] != 0 && error("gmshModelMeshGetJacobian returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     jacobians = unsafe_wrap(Array, api_jacobians_[], api_jacobians_n_[], own=true)
     determinants = unsafe_wrap(Array, api_determinants_[], api_determinants_n_[], own=true)
     coord = unsafe_wrap(Array, api_coord_[], api_coord_n_[], own=true)
@@ -1852,7 +1852,7 @@ function getBasisFunctions(elementType, localCoord, functionSpaceType, wantedOri
     ccall((:gmshModelMeshGetBasisFunctions, gmsh.lib), Cvoid,
           (Cint, Ptr{Cdouble}, Csize_t, Ptr{Cchar}, Ptr{Cint}, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Ptr{Cint}, Ptr{Cint}, Csize_t, Ptr{Cint}),
           elementType, convert(Vector{Cdouble}, localCoord), length(localCoord), functionSpaceType, api_numComponents_, api_basisFunctions_, api_basisFunctions_n_, api_numOrientations_, convert(Vector{Cint}, wantedOrientations), length(wantedOrientations), ierr)
-    ierr[] != 0 && error("gmshModelMeshGetBasisFunctions returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     basisFunctions = unsafe_wrap(Array, api_basisFunctions_[], api_basisFunctions_n_[], own=true)
     return api_numComponents_[], basisFunctions, api_numOrientations_[]
 end
@@ -1875,7 +1875,7 @@ function getBasisFunctionsOrientationForElements(elementType, functionSpaceType,
     ccall((:gmshModelMeshGetBasisFunctionsOrientationForElements, gmsh.lib), Cvoid,
           (Cint, Ptr{Cchar}, Ptr{Ptr{Cint}}, Ptr{Csize_t}, Cint, Csize_t, Csize_t, Ptr{Cint}),
           elementType, functionSpaceType, api_basisFunctionsOrientation_, api_basisFunctionsOrientation_n_, tag, task, numTasks, ierr)
-    ierr[] != 0 && error("gmshModelMeshGetBasisFunctionsOrientationForElements returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     basisFunctionsOrientation = unsafe_wrap(Array, api_basisFunctionsOrientation_[], api_basisFunctionsOrientation_n_[], own=true)
     return basisFunctionsOrientation
 end
@@ -1893,7 +1893,7 @@ function getBasisFunctionsOrientationForElement(elementTag, functionSpaceType)
     ccall((:gmshModelMeshGetBasisFunctionsOrientationForElement, gmsh.lib), Cvoid,
           (Csize_t, Ptr{Cchar}, Ptr{Cint}, Ptr{Cint}),
           elementTag, functionSpaceType, api_basisFunctionsOrientation_, ierr)
-    ierr[] != 0 && error("gmshModelMeshGetBasisFunctionsOrientationForElement returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return api_basisFunctionsOrientation_[]
 end
 
@@ -1907,11 +1907,11 @@ Return an integer value.
 """
 function getNumberOfOrientations(elementType, functionSpaceType)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelMeshGetNumberOfOrientations, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelMeshGetNumberOfOrientations, gmsh.lib), Cint,
           (Cint, Ptr{Cchar}, Ptr{Cint}),
           elementType, functionSpaceType, ierr)
-    ierr[] != 0 && error("gmshModelMeshGetNumberOfOrientations returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -1930,7 +1930,7 @@ function getEdgeNumber(edgeNodes)
     ccall((:gmshModelMeshGetEdgeNumber, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Ptr{Ptr{Cint}}, Ptr{Csize_t}, Ptr{Cint}),
           convert(Vector{Cint}, edgeNodes), length(edgeNodes), api_edgeNum_, api_edgeNum_n_, ierr)
-    ierr[] != 0 && error("gmshModelMeshGetEdgeNumber returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     edgeNum = unsafe_wrap(Array, api_edgeNum_[], api_edgeNum_n_[], own=true)
     return edgeNum
 end
@@ -1951,7 +1951,7 @@ function getLocalMultipliersForHcurl0(elementType, tag = -1)
     ccall((:gmshModelMeshGetLocalMultipliersForHcurl0, gmsh.lib), Cvoid,
           (Cint, Ptr{Ptr{Cint}}, Ptr{Csize_t}, Cint, Ptr{Cint}),
           elementType, api_localMultipliers_, api_localMultipliers_n_, tag, ierr)
-    ierr[] != 0 && error("gmshModelMeshGetLocalMultipliersForHcurl0 returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     localMultipliers = unsafe_wrap(Array, api_localMultipliers_[], api_localMultipliers_n_[], own=true)
     return localMultipliers
 end
@@ -1977,7 +1977,7 @@ function getKeysForElements(elementType, functionSpaceType, tag = -1, returnCoor
     ccall((:gmshModelMeshGetKeysForElements, gmsh.lib), Cvoid,
           (Cint, Ptr{Cchar}, Ptr{Ptr{Cint}}, Ptr{Csize_t}, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Cint, Cint, Ptr{Cint}),
           elementType, functionSpaceType, api_keys_, api_keys_n_, api_coord_, api_coord_n_, tag, returnCoord, ierr)
-    ierr[] != 0 && error("gmshModelMeshGetKeysForElements returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     tmp_api_keys_ = unsafe_wrap(Array, api_keys_[], api_keys_n_[], own=true)
     keys = [ (tmp_api_keys_[i], tmp_api_keys_[i+1]) for i in 1:2:length(tmp_api_keys_) ]
     coord = unsafe_wrap(Array, api_coord_[], api_coord_n_[], own=true)
@@ -2000,7 +2000,7 @@ function getKeysForElement(elementTag, functionSpaceType, returnCoord = true)
     ccall((:gmshModelMeshGetKeysForElement, gmsh.lib), Cvoid,
           (Csize_t, Ptr{Cchar}, Ptr{Ptr{Cint}}, Ptr{Csize_t}, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Cint, Ptr{Cint}),
           elementTag, functionSpaceType, api_keys_, api_keys_n_, api_coord_, api_coord_n_, returnCoord, ierr)
-    ierr[] != 0 && error("gmshModelMeshGetKeysForElement returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     tmp_api_keys_ = unsafe_wrap(Array, api_keys_[], api_keys_n_[], own=true)
     keys = [ (tmp_api_keys_[i], tmp_api_keys_[i+1]) for i in 1:2:length(tmp_api_keys_) ]
     coord = unsafe_wrap(Array, api_coord_[], api_coord_n_[], own=true)
@@ -2017,11 +2017,11 @@ Return an integer value.
 """
 function getNumberOfKeysForElements(elementType, functionSpaceType)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelMeshGetNumberOfKeysForElements, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelMeshGetNumberOfKeysForElements, gmsh.lib), Cint,
           (Cint, Ptr{Cchar}, Ptr{Cint}),
           elementType, functionSpaceType, ierr)
-    ierr[] != 0 && error("gmshModelMeshGetNumberOfKeysForElements returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -2045,7 +2045,7 @@ function getInformationForElements(keys, elementType, functionSpaceType)
     ccall((:gmshModelMeshGetInformationForElements, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Cint, Ptr{Cchar}, Ptr{Ptr{Cint}}, Ptr{Csize_t}, Ptr{Cint}),
           api_keys_, api_keys_n_, elementType, functionSpaceType, api_infoKeys_, api_infoKeys_n_, ierr)
-    ierr[] != 0 && error("gmshModelMeshGetInformationForElements returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     tmp_api_infoKeys_ = unsafe_wrap(Array, api_infoKeys_[], api_infoKeys_n_[], own=true)
     infoKeys = [ (tmp_api_infoKeys_[i], tmp_api_infoKeys_[i+1]) for i in 1:2:length(tmp_api_infoKeys_) ]
     return infoKeys
@@ -2070,7 +2070,7 @@ function getBarycenters(elementType, tag, fast, primary, task = 0, numTasks = 1)
     ccall((:gmshModelMeshGetBarycenters, gmsh.lib), Cvoid,
           (Cint, Cint, Cint, Cint, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Csize_t, Csize_t, Ptr{Cint}),
           elementType, tag, fast, primary, api_barycenters_, api_barycenters_n_, task, numTasks, ierr)
-    ierr[] != 0 && error("gmshModelMeshGetBarycenters returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     barycenters = unsafe_wrap(Array, api_barycenters_[], api_barycenters_n_[], own=true)
     return barycenters
 end
@@ -2095,7 +2095,7 @@ function getElementEdgeNodes(elementType, tag = -1, primary = false, task = 0, n
     ccall((:gmshModelMeshGetElementEdgeNodes, gmsh.lib), Cvoid,
           (Cint, Ptr{Ptr{Csize_t}}, Ptr{Csize_t}, Cint, Cint, Csize_t, Csize_t, Ptr{Cint}),
           elementType, api_nodeTags_, api_nodeTags_n_, tag, primary, task, numTasks, ierr)
-    ierr[] != 0 && error("gmshModelMeshGetElementEdgeNodes returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     nodeTags = unsafe_wrap(Array, api_nodeTags_[], api_nodeTags_n_[], own=true)
     return nodeTags
 end
@@ -2121,7 +2121,7 @@ function getElementFaceNodes(elementType, faceType, tag = -1, primary = false, t
     ccall((:gmshModelMeshGetElementFaceNodes, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Ptr{Csize_t}}, Ptr{Csize_t}, Cint, Cint, Csize_t, Csize_t, Ptr{Cint}),
           elementType, faceType, api_nodeTags_, api_nodeTags_n_, tag, primary, task, numTasks, ierr)
-    ierr[] != 0 && error("gmshModelMeshGetElementFaceNodes returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     nodeTags = unsafe_wrap(Array, api_nodeTags_[], api_nodeTags_n_[], own=true)
     return nodeTags
 end
@@ -2143,7 +2143,7 @@ function getGhostElements(dim, tag)
     ccall((:gmshModelMeshGetGhostElements, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Ptr{Csize_t}}, Ptr{Csize_t}, Ptr{Ptr{Cint}}, Ptr{Csize_t}, Ptr{Cint}),
           dim, tag, api_elementTags_, api_elementTags_n_, api_partitions_, api_partitions_n_, ierr)
-    ierr[] != 0 && error("gmshModelMeshGetGhostElements returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     elementTags = unsafe_wrap(Array, api_elementTags_[], api_elementTags_n_[], own=true)
     partitions = unsafe_wrap(Array, api_partitions_[], api_partitions_n_[], own=true)
     return elementTags, partitions
@@ -2162,7 +2162,7 @@ function setSize(dimTags, size)
     ccall((:gmshModelMeshSetSize, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Cdouble, Ptr{Cint}),
           api_dimTags_, api_dimTags_n_, size, ierr)
-    ierr[] != 0 && error("gmshModelMeshSetSize returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -2178,7 +2178,7 @@ function setSizeAtParametricPoints(dim, tag, parametricCoord, sizes)
     ccall((:gmshModelMeshSetSizeAtParametricPoints, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Cdouble}, Csize_t, Ptr{Cdouble}, Csize_t, Ptr{Cint}),
           dim, tag, convert(Vector{Cdouble}, parametricCoord), length(parametricCoord), convert(Vector{Cdouble}, sizes), length(sizes), ierr)
-    ierr[] != 0 && error("gmshModelMeshSetSizeAtParametricPoints returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -2195,7 +2195,7 @@ function setTransfiniteCurve(tag, numNodes, meshType = "Progression", coef = 1.)
     ccall((:gmshModelMeshSetTransfiniteCurve, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Cchar}, Cdouble, Ptr{Cint}),
           tag, numNodes, meshType, coef, ierr)
-    ierr[] != 0 && error("gmshModelMeshSetTransfiniteCurve returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -2214,7 +2214,7 @@ function setTransfiniteSurface(tag, arrangement = "Left", cornerTags = Cint[])
     ccall((:gmshModelMeshSetTransfiniteSurface, gmsh.lib), Cvoid,
           (Cint, Ptr{Cchar}, Ptr{Cint}, Csize_t, Ptr{Cint}),
           tag, arrangement, convert(Vector{Cint}, cornerTags), length(cornerTags), ierr)
-    ierr[] != 0 && error("gmshModelMeshSetTransfiniteSurface returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -2230,7 +2230,7 @@ function setTransfiniteVolume(tag, cornerTags = Cint[])
     ccall((:gmshModelMeshSetTransfiniteVolume, gmsh.lib), Cvoid,
           (Cint, Ptr{Cint}, Csize_t, Ptr{Cint}),
           tag, convert(Vector{Cint}, cornerTags), length(cornerTags), ierr)
-    ierr[] != 0 && error("gmshModelMeshSetTransfiniteVolume returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -2246,7 +2246,7 @@ function setRecombine(dim, tag)
     ccall((:gmshModelMeshSetRecombine, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Cint}),
           dim, tag, ierr)
-    ierr[] != 0 && error("gmshModelMeshSetRecombine returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -2261,7 +2261,7 @@ function setSmoothing(dim, tag, val)
     ccall((:gmshModelMeshSetSmoothing, gmsh.lib), Cvoid,
           (Cint, Cint, Cint, Ptr{Cint}),
           dim, tag, val, ierr)
-    ierr[] != 0 && error("gmshModelMeshSetSmoothing returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -2278,7 +2278,7 @@ function setReverse(dim, tag, val = true)
     ccall((:gmshModelMeshSetReverse, gmsh.lib), Cvoid,
           (Cint, Cint, Cint, Ptr{Cint}),
           dim, tag, val, ierr)
-    ierr[] != 0 && error("gmshModelMeshSetReverse returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -2293,7 +2293,7 @@ function setAlgorithm(dim, tag, val)
     ccall((:gmshModelMeshSetAlgorithm, gmsh.lib), Cvoid,
           (Cint, Cint, Cint, Ptr{Cint}),
           dim, tag, val, ierr)
-    ierr[] != 0 && error("gmshModelMeshSetAlgorithm returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -2309,7 +2309,7 @@ function setSizeFromBoundary(dim, tag, val)
     ccall((:gmshModelMeshSetSizeFromBoundary, gmsh.lib), Cvoid,
           (Cint, Cint, Cint, Ptr{Cint}),
           dim, tag, val, ierr)
-    ierr[] != 0 && error("gmshModelMeshSetSizeFromBoundary returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -2325,7 +2325,7 @@ function setCompound(dim, tags)
     ccall((:gmshModelMeshSetCompound, gmsh.lib), Cvoid,
           (Cint, Ptr{Cint}, Csize_t, Ptr{Cint}),
           dim, convert(Vector{Cint}, tags), length(tags), ierr)
-    ierr[] != 0 && error("gmshModelMeshSetCompound returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -2341,7 +2341,7 @@ function setOutwardOrientation(tag)
     ccall((:gmshModelMeshSetOutwardOrientation, gmsh.lib), Cvoid,
           (Cint, Ptr{Cint}),
           tag, ierr)
-    ierr[] != 0 && error("gmshModelMeshSetOutwardOrientation returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -2359,7 +2359,7 @@ function embed(dim, tags, inDim, inTag)
     ccall((:gmshModelMeshEmbed, gmsh.lib), Cvoid,
           (Cint, Ptr{Cint}, Csize_t, Cint, Cint, Ptr{Cint}),
           dim, convert(Vector{Cint}, tags), length(tags), inDim, inTag, ierr)
-    ierr[] != 0 && error("gmshModelMeshEmbed returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -2377,7 +2377,7 @@ function removeEmbedded(dimTags, dim = -1)
     ccall((:gmshModelMeshRemoveEmbedded, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Cint, Ptr{Cint}),
           api_dimTags_, api_dimTags_n_, dim, ierr)
-    ierr[] != 0 && error("gmshModelMeshRemoveEmbedded returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -2392,7 +2392,7 @@ function reorderElements(elementType, tag, ordering)
     ccall((:gmshModelMeshReorderElements, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Csize_t}, Csize_t, Ptr{Cint}),
           elementType, tag, convert(Vector{Csize_t}, ordering), length(ordering), ierr)
-    ierr[] != 0 && error("gmshModelMeshReorderElements returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -2406,7 +2406,7 @@ function renumberNodes()
     ccall((:gmshModelMeshRenumberNodes, gmsh.lib), Cvoid,
           (Ptr{Cint},),
           ierr)
-    ierr[] != 0 && error("gmshModelMeshRenumberNodes returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -2420,7 +2420,7 @@ function renumberElements()
     ccall((:gmshModelMeshRenumberElements, gmsh.lib), Cvoid,
           (Ptr{Cint},),
           ierr)
-    ierr[] != 0 && error("gmshModelMeshRenumberElements returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -2440,7 +2440,7 @@ function setPeriodic(dim, tags, tagsMaster, affineTransform)
     ccall((:gmshModelMeshSetPeriodic, gmsh.lib), Cvoid,
           (Cint, Ptr{Cint}, Csize_t, Ptr{Cint}, Csize_t, Ptr{Cdouble}, Csize_t, Ptr{Cint}),
           dim, convert(Vector{Cint}, tags), length(tags), convert(Vector{Cint}, tagsMaster), length(tagsMaster), convert(Vector{Cdouble}, affineTransform), length(affineTransform), ierr)
-    ierr[] != 0 && error("gmshModelMeshSetPeriodic returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -2466,7 +2466,7 @@ function getPeriodicNodes(dim, tag, includeHighOrderNodes = false)
     ccall((:gmshModelMeshGetPeriodicNodes, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Cint}, Ptr{Ptr{Csize_t}}, Ptr{Csize_t}, Ptr{Ptr{Csize_t}}, Ptr{Csize_t}, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Cint, Ptr{Cint}),
           dim, tag, api_tagMaster_, api_nodeTags_, api_nodeTags_n_, api_nodeTagsMaster_, api_nodeTagsMaster_n_, api_affineTransform_, api_affineTransform_n_, includeHighOrderNodes, ierr)
-    ierr[] != 0 && error("gmshModelMeshGetPeriodicNodes returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     nodeTags = unsafe_wrap(Array, api_nodeTags_[], api_nodeTags_n_[], own=true)
     nodeTagsMaster = unsafe_wrap(Array, api_nodeTagsMaster_[], api_nodeTagsMaster_n_[], own=true)
     affineTransform = unsafe_wrap(Array, api_affineTransform_[], api_affineTransform_n_[], own=true)
@@ -2483,7 +2483,7 @@ function removeDuplicateNodes()
     ccall((:gmshModelMeshRemoveDuplicateNodes, gmsh.lib), Cvoid,
           (Ptr{Cint},),
           ierr)
-    ierr[] != 0 && error("gmshModelMeshRemoveDuplicateNodes returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -2498,7 +2498,7 @@ function splitQuadrangles(quality = 1., tag = -1)
     ccall((:gmshModelMeshSplitQuadrangles, gmsh.lib), Cvoid,
           (Cdouble, Cint, Ptr{Cint}),
           quality, tag, ierr)
-    ierr[] != 0 && error("gmshModelMeshSplitQuadrangles returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -2517,7 +2517,7 @@ function classifySurfaces(angle, boundary = true, forReparametrization = false,
     ccall((:gmshModelMeshClassifySurfaces, gmsh.lib), Cvoid,
           (Cdouble, Cint, Cint, Cdouble, Ptr{Cint}),
           angle, boundary, forReparametrization, curveAngle, ierr)
-    ierr[] != 0 && error("gmshModelMeshClassifySurfaces returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -2537,7 +2537,7 @@ function createGeometry(dimTags = Tuple{Cint,Cint}[])
     ccall((:gmshModelMeshCreateGeometry, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Ptr{Cint}),
           api_dimTags_, api_dimTags_n_, ierr)
-    ierr[] != 0 && error("gmshModelMeshCreateGeometry returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -2555,7 +2555,7 @@ function createTopology(makeSimplyConnected = true, exportDiscrete = true)
     ccall((:gmshModelMeshCreateTopology, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Cint}),
           makeSimplyConnected, exportDiscrete, ierr)
-    ierr[] != 0 && error("gmshModelMeshCreateTopology returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -2576,7 +2576,7 @@ function computeHomology(domainTags = Cint[], subdomainTags = Cint[], dims = Cin
     ccall((:gmshModelMeshComputeHomology, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Ptr{Cint}, Csize_t, Ptr{Cint}, Csize_t, Ptr{Cint}),
           convert(Vector{Cint}, domainTags), length(domainTags), convert(Vector{Cint}, subdomainTags), length(subdomainTags), convert(Vector{Cint}, dims), length(dims), ierr)
-    ierr[] != 0 && error("gmshModelMeshComputeHomology returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -2597,7 +2597,7 @@ function computeCohomology(domainTags = Cint[], subdomainTags = Cint[], dims = C
     ccall((:gmshModelMeshComputeCohomology, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Ptr{Cint}, Csize_t, Ptr{Cint}, Csize_t, Ptr{Cint}),
           convert(Vector{Cint}, domainTags), length(domainTags), convert(Vector{Cint}, subdomainTags), length(subdomainTags), convert(Vector{Cint}, dims), length(dims), ierr)
-    ierr[] != 0 && error("gmshModelMeshComputeCohomology returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -2616,7 +2616,7 @@ function computeCrossField()
     ccall((:gmshModelMeshComputeCrossField, gmsh.lib), Cvoid,
           (Ptr{Ptr{Cint}}, Ptr{Csize_t}, Ptr{Cint}),
           api_viewTags_, api_viewTags_n_, ierr)
-    ierr[] != 0 && error("gmshModelMeshComputeCrossField returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     viewTags = unsafe_wrap(Array, api_viewTags_[], api_viewTags_n_[], own=true)
     return viewTags
 end
@@ -2641,11 +2641,11 @@ Return an integer value.
 """
 function add(fieldType, tag = -1)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelMeshFieldAdd, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelMeshFieldAdd, gmsh.lib), Cint,
           (Ptr{Cchar}, Cint, Ptr{Cint}),
           fieldType, tag, ierr)
-    ierr[] != 0 && error("gmshModelMeshFieldAdd returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -2658,7 +2658,7 @@ function remove(tag)
     ccall((:gmshModelMeshFieldRemove, gmsh.lib), Cvoid,
           (Cint, Ptr{Cint}),
           tag, ierr)
-    ierr[] != 0 && error("gmshModelMeshFieldRemove returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -2672,7 +2672,7 @@ function setNumber(tag, option, value)
     ccall((:gmshModelMeshFieldSetNumber, gmsh.lib), Cvoid,
           (Cint, Ptr{Cchar}, Cdouble, Ptr{Cint}),
           tag, option, value, ierr)
-    ierr[] != 0 && error("gmshModelMeshFieldSetNumber returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -2686,7 +2686,7 @@ function setString(tag, option, value)
     ccall((:gmshModelMeshFieldSetString, gmsh.lib), Cvoid,
           (Cint, Ptr{Cchar}, Ptr{Cchar}, Ptr{Cint}),
           tag, option, value, ierr)
-    ierr[] != 0 && error("gmshModelMeshFieldSetString returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -2700,7 +2700,7 @@ function setNumbers(tag, option, value)
     ccall((:gmshModelMeshFieldSetNumbers, gmsh.lib), Cvoid,
           (Cint, Ptr{Cchar}, Ptr{Cdouble}, Csize_t, Ptr{Cint}),
           tag, option, convert(Vector{Cdouble}, value), length(value), ierr)
-    ierr[] != 0 && error("gmshModelMeshFieldSetNumbers returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -2714,7 +2714,7 @@ function setAsBackgroundMesh(tag)
     ccall((:gmshModelMeshFieldSetAsBackgroundMesh, gmsh.lib), Cvoid,
           (Cint, Ptr{Cint}),
           tag, ierr)
-    ierr[] != 0 && error("gmshModelMeshFieldSetAsBackgroundMesh returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -2728,7 +2728,7 @@ function setAsBoundaryLayer(tag)
     ccall((:gmshModelMeshFieldSetAsBoundaryLayer, gmsh.lib), Cvoid,
           (Cint, Ptr{Cint}),
           tag, ierr)
-    ierr[] != 0 && error("gmshModelMeshFieldSetAsBoundaryLayer returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -2759,11 +2759,11 @@ Return an integer value.
 """
 function addPoint(x, y, z, meshSize = 0., tag = -1)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelGeoAddPoint, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelGeoAddPoint, gmsh.lib), Cint,
           (Cdouble, Cdouble, Cdouble, Cdouble, Cint, Ptr{Cint}),
           x, y, z, meshSize, tag, ierr)
-    ierr[] != 0 && error("gmshModelGeoAddPoint returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -2777,11 +2777,11 @@ Return an integer value.
 """
 function addLine(startTag, endTag, tag = -1)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelGeoAddLine, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelGeoAddLine, gmsh.lib), Cint,
           (Cint, Cint, Cint, Ptr{Cint}),
           startTag, endTag, tag, ierr)
-    ierr[] != 0 && error("gmshModelGeoAddLine returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -2797,11 +2797,11 @@ Return an integer value.
 """
 function addCircleArc(startTag, centerTag, endTag, tag = -1, nx = 0., ny = 0., nz = 0.)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelGeoAddCircleArc, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelGeoAddCircleArc, gmsh.lib), Cint,
           (Cint, Cint, Cint, Cint, Cdouble, Cdouble, Cdouble, Ptr{Cint}),
           startTag, centerTag, endTag, tag, nx, ny, nz, ierr)
-    ierr[] != 0 && error("gmshModelGeoAddCircleArc returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -2817,11 +2817,11 @@ Return an integer value.
 """
 function addEllipseArc(startTag, centerTag, majorTag, endTag, tag = -1, nx = 0., ny = 0., nz = 0.)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelGeoAddEllipseArc, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelGeoAddEllipseArc, gmsh.lib), Cint,
           (Cint, Cint, Cint, Cint, Cint, Cdouble, Cdouble, Cdouble, Ptr{Cint}),
           startTag, centerTag, majorTag, endTag, tag, nx, ny, nz, ierr)
-    ierr[] != 0 && error("gmshModelGeoAddEllipseArc returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -2836,11 +2836,11 @@ Return an integer value.
 """
 function addSpline(pointTags, tag = -1)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelGeoAddSpline, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelGeoAddSpline, gmsh.lib), Cint,
           (Ptr{Cint}, Csize_t, Cint, Ptr{Cint}),
           convert(Vector{Cint}, pointTags), length(pointTags), tag, ierr)
-    ierr[] != 0 && error("gmshModelGeoAddSpline returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -2855,11 +2855,11 @@ Return an integer value.
 """
 function addBSpline(pointTags, tag = -1)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelGeoAddBSpline, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelGeoAddBSpline, gmsh.lib), Cint,
           (Ptr{Cint}, Csize_t, Cint, Ptr{Cint}),
           convert(Vector{Cint}, pointTags), length(pointTags), tag, ierr)
-    ierr[] != 0 && error("gmshModelGeoAddBSpline returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -2873,11 +2873,11 @@ Return an integer value.
 """
 function addBezier(pointTags, tag = -1)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelGeoAddBezier, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelGeoAddBezier, gmsh.lib), Cint,
           (Ptr{Cint}, Csize_t, Cint, Ptr{Cint}),
           convert(Vector{Cint}, pointTags), length(pointTags), tag, ierr)
-    ierr[] != 0 && error("gmshModelGeoAddBezier returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -2892,11 +2892,11 @@ Return an integer value.
 """
 function addPolyline(pointTags, tag = -1)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelGeoAddPolyline, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelGeoAddPolyline, gmsh.lib), Cint,
           (Ptr{Cint}, Csize_t, Cint, Ptr{Cint}),
           convert(Vector{Cint}, pointTags), length(pointTags), tag, ierr)
-    ierr[] != 0 && error("gmshModelGeoAddPolyline returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -2911,11 +2911,11 @@ Return an integer value.
 """
 function addCompoundSpline(curveTags, numIntervals = 5, tag = -1)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelGeoAddCompoundSpline, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelGeoAddCompoundSpline, gmsh.lib), Cint,
           (Ptr{Cint}, Csize_t, Cint, Cint, Ptr{Cint}),
           convert(Vector{Cint}, curveTags), length(curveTags), numIntervals, tag, ierr)
-    ierr[] != 0 && error("gmshModelGeoAddCompoundSpline returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -2930,11 +2930,11 @@ Return an integer value.
 """
 function addCompoundBSpline(curveTags, numIntervals = 20, tag = -1)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelGeoAddCompoundBSpline, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelGeoAddCompoundBSpline, gmsh.lib), Cint,
           (Ptr{Cint}, Csize_t, Cint, Cint, Ptr{Cint}),
           convert(Vector{Cint}, curveTags), length(curveTags), numIntervals, tag, ierr)
-    ierr[] != 0 && error("gmshModelGeoAddCompoundBSpline returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -2950,11 +2950,11 @@ Return an integer value.
 """
 function addCurveLoop(curveTags, tag = -1)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelGeoAddCurveLoop, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelGeoAddCurveLoop, gmsh.lib), Cint,
           (Ptr{Cint}, Csize_t, Cint, Ptr{Cint}),
           convert(Vector{Cint}, curveTags), length(curveTags), tag, ierr)
-    ierr[] != 0 && error("gmshModelGeoAddCurveLoop returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -2969,11 +2969,11 @@ Return an integer value.
 """
 function addPlaneSurface(wireTags, tag = -1)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelGeoAddPlaneSurface, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelGeoAddPlaneSurface, gmsh.lib), Cint,
           (Ptr{Cint}, Csize_t, Cint, Ptr{Cint}),
           convert(Vector{Cint}, wireTags), length(wireTags), tag, ierr)
-    ierr[] != 0 && error("gmshModelGeoAddPlaneSurface returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -2988,11 +2988,11 @@ Return an integer value.
 """
 function addSurfaceFilling(wireTags, tag = -1, sphereCenterTag = -1)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelGeoAddSurfaceFilling, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelGeoAddSurfaceFilling, gmsh.lib), Cint,
           (Ptr{Cint}, Csize_t, Cint, Cint, Ptr{Cint}),
           convert(Vector{Cint}, wireTags), length(wireTags), tag, sphereCenterTag, ierr)
-    ierr[] != 0 && error("gmshModelGeoAddSurfaceFilling returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -3006,11 +3006,11 @@ Return an integer value.
 """
 function addSurfaceLoop(surfaceTags, tag = -1)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelGeoAddSurfaceLoop, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelGeoAddSurfaceLoop, gmsh.lib), Cint,
           (Ptr{Cint}, Csize_t, Cint, Ptr{Cint}),
           convert(Vector{Cint}, surfaceTags), length(surfaceTags), tag, ierr)
-    ierr[] != 0 && error("gmshModelGeoAddSurfaceLoop returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -3025,11 +3025,11 @@ Return an integer value.
 """
 function addVolume(shellTags, tag = -1)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelGeoAddVolume, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelGeoAddVolume, gmsh.lib), Cint,
           (Ptr{Cint}, Csize_t, Cint, Ptr{Cint}),
           convert(Vector{Cint}, shellTags), length(shellTags), tag, ierr)
-    ierr[] != 0 && error("gmshModelGeoAddVolume returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -3053,7 +3053,7 @@ function extrude(dimTags, dx, dy, dz, numElements = Cint[], heights = Cdouble[],
     ccall((:gmshModelGeoExtrude, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Cdouble, Cdouble, Cdouble, Ptr{Ptr{Cint}}, Ptr{Csize_t}, Ptr{Cint}, Csize_t, Ptr{Cdouble}, Csize_t, Cint, Ptr{Cint}),
           api_dimTags_, api_dimTags_n_, dx, dy, dz, api_outDimTags_, api_outDimTags_n_, convert(Vector{Cint}, numElements), length(numElements), convert(Vector{Cdouble}, heights), length(heights), recombine, ierr)
-    ierr[] != 0 && error("gmshModelGeoExtrude returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     tmp_api_outDimTags_ = unsafe_wrap(Array, api_outDimTags_[], api_outDimTags_n_[], own=true)
     outDimTags = [ (tmp_api_outDimTags_[i], tmp_api_outDimTags_[i+1]) for i in 1:2:length(tmp_api_outDimTags_) ]
     return outDimTags
@@ -3081,7 +3081,7 @@ function revolve(dimTags, x, y, z, ax, ay, az, angle, numElements = Cint[], heig
     ccall((:gmshModelGeoRevolve, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Ptr{Ptr{Cint}}, Ptr{Csize_t}, Ptr{Cint}, Csize_t, Ptr{Cdouble}, Csize_t, Cint, Ptr{Cint}),
           api_dimTags_, api_dimTags_n_, x, y, z, ax, ay, az, angle, api_outDimTags_, api_outDimTags_n_, convert(Vector{Cint}, numElements), length(numElements), convert(Vector{Cdouble}, heights), length(heights), recombine, ierr)
-    ierr[] != 0 && error("gmshModelGeoRevolve returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     tmp_api_outDimTags_ = unsafe_wrap(Array, api_outDimTags_[], api_outDimTags_n_[], own=true)
     outDimTags = [ (tmp_api_outDimTags_[i], tmp_api_outDimTags_[i+1]) for i in 1:2:length(tmp_api_outDimTags_) ]
     return outDimTags
@@ -3110,7 +3110,7 @@ function twist(dimTags, x, y, z, dx, dy, dz, ax, ay, az, angle, numElements = Ci
     ccall((:gmshModelGeoTwist, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Ptr{Ptr{Cint}}, Ptr{Csize_t}, Ptr{Cint}, Csize_t, Ptr{Cdouble}, Csize_t, Cint, Ptr{Cint}),
           api_dimTags_, api_dimTags_n_, x, y, z, dx, dy, dz, ax, ay, az, angle, api_outDimTags_, api_outDimTags_n_, convert(Vector{Cint}, numElements), length(numElements), convert(Vector{Cdouble}, heights), length(heights), recombine, ierr)
-    ierr[] != 0 && error("gmshModelGeoTwist returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     tmp_api_outDimTags_ = unsafe_wrap(Array, api_outDimTags_[], api_outDimTags_n_[], own=true)
     outDimTags = [ (tmp_api_outDimTags_[i], tmp_api_outDimTags_[i+1]) for i in 1:2:length(tmp_api_outDimTags_) ]
     return outDimTags
@@ -3128,7 +3128,7 @@ function translate(dimTags, dx, dy, dz)
     ccall((:gmshModelGeoTranslate, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Cdouble, Cdouble, Cdouble, Ptr{Cint}),
           api_dimTags_, api_dimTags_n_, dx, dy, dz, ierr)
-    ierr[] != 0 && error("gmshModelGeoTranslate returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -3146,7 +3146,7 @@ function rotate(dimTags, x, y, z, ax, ay, az, angle)
     ccall((:gmshModelGeoRotate, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Ptr{Cint}),
           api_dimTags_, api_dimTags_n_, x, y, z, ax, ay, az, angle, ierr)
-    ierr[] != 0 && error("gmshModelGeoRotate returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -3164,7 +3164,7 @@ function dilate(dimTags, x, y, z, a, b, c)
     ccall((:gmshModelGeoDilate, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Ptr{Cint}),
           api_dimTags_, api_dimTags_n_, x, y, z, a, b, c, ierr)
-    ierr[] != 0 && error("gmshModelGeoDilate returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -3181,7 +3181,7 @@ function mirror(dimTags, a, b, c, d)
     ccall((:gmshModelGeoMirror, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Cdouble, Cdouble, Cdouble, Cdouble, Ptr{Cint}),
           api_dimTags_, api_dimTags_n_, a, b, c, d, ierr)
-    ierr[] != 0 && error("gmshModelGeoMirror returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -3199,7 +3199,7 @@ function symmetrize(dimTags, a, b, c, d)
     ccall((:gmshModelGeoSymmetrize, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Cdouble, Cdouble, Cdouble, Cdouble, Ptr{Cint}),
           api_dimTags_, api_dimTags_n_, a, b, c, d, ierr)
-    ierr[] != 0 && error("gmshModelGeoSymmetrize returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -3219,7 +3219,7 @@ function copy(dimTags)
     ccall((:gmshModelGeoCopy, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Ptr{Ptr{Cint}}, Ptr{Csize_t}, Ptr{Cint}),
           api_dimTags_, api_dimTags_n_, api_outDimTags_, api_outDimTags_n_, ierr)
-    ierr[] != 0 && error("gmshModelGeoCopy returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     tmp_api_outDimTags_ = unsafe_wrap(Array, api_outDimTags_[], api_outDimTags_n_[], own=true)
     outDimTags = [ (tmp_api_outDimTags_[i], tmp_api_outDimTags_[i+1]) for i in 1:2:length(tmp_api_outDimTags_) ]
     return outDimTags
@@ -3238,7 +3238,7 @@ function remove(dimTags, recursive = false)
     ccall((:gmshModelGeoRemove, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Cint, Ptr{Cint}),
           api_dimTags_, api_dimTags_n_, recursive, ierr)
-    ierr[] != 0 && error("gmshModelGeoRemove returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -3253,7 +3253,7 @@ function removeAllDuplicates()
     ccall((:gmshModelGeoRemoveAllDuplicates, gmsh.lib), Cvoid,
           (Ptr{Cint},),
           ierr)
-    ierr[] != 0 && error("gmshModelGeoRemoveAllDuplicates returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -3272,7 +3272,7 @@ function splitCurve(tag, pointTags)
     ccall((:gmshModelGeoSplitCurve, gmsh.lib), Cvoid,
           (Cint, Ptr{Cint}, Csize_t, Ptr{Ptr{Cint}}, Ptr{Csize_t}, Ptr{Cint}),
           tag, convert(Vector{Cint}, pointTags), length(pointTags), api_curveTags_, api_curveTags_n_, ierr)
-    ierr[] != 0 && error("gmshModelGeoSplitCurve returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     curveTags = unsafe_wrap(Array, api_curveTags_[], api_curveTags_n_[], own=true)
     return curveTags
 end
@@ -3287,11 +3287,11 @@ Return an integer value.
 """
 function getMaxTag(dim)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelGeoGetMaxTag, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelGeoGetMaxTag, gmsh.lib), Cint,
           (Cint, Ptr{Cint}),
           dim, ierr)
-    ierr[] != 0 && error("gmshModelGeoGetMaxTag returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -3305,7 +3305,7 @@ function setMaxTag(dim, maxTag)
     ccall((:gmshModelGeoSetMaxTag, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Cint}),
           dim, maxTag, ierr)
-    ierr[] != 0 && error("gmshModelGeoSetMaxTag returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -3321,7 +3321,7 @@ function synchronize()
     ccall((:gmshModelGeoSynchronize, gmsh.lib), Cvoid,
           (Ptr{Cint},),
           ierr)
-    ierr[] != 0 && error("gmshModelGeoSynchronize returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -3347,7 +3347,7 @@ function setSize(dimTags, size)
     ccall((:gmshModelGeoMeshSetSize, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Cdouble, Ptr{Cint}),
           api_dimTags_, api_dimTags_n_, size, ierr)
-    ierr[] != 0 && error("gmshModelGeoMeshSetSize returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -3364,7 +3364,7 @@ function setTransfiniteCurve(tag, nPoints, meshType = "Progression", coef = 1.)
     ccall((:gmshModelGeoMeshSetTransfiniteCurve, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Cchar}, Cdouble, Ptr{Cint}),
           tag, nPoints, meshType, coef, ierr)
-    ierr[] != 0 && error("gmshModelGeoMeshSetTransfiniteCurve returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -3383,7 +3383,7 @@ function setTransfiniteSurface(tag, arrangement = "Left", cornerTags = Cint[])
     ccall((:gmshModelGeoMeshSetTransfiniteSurface, gmsh.lib), Cvoid,
           (Cint, Ptr{Cchar}, Ptr{Cint}, Csize_t, Ptr{Cint}),
           tag, arrangement, convert(Vector{Cint}, cornerTags), length(cornerTags), ierr)
-    ierr[] != 0 && error("gmshModelGeoMeshSetTransfiniteSurface returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -3399,7 +3399,7 @@ function setTransfiniteVolume(tag, cornerTags = Cint[])
     ccall((:gmshModelGeoMeshSetTransfiniteVolume, gmsh.lib), Cvoid,
           (Cint, Ptr{Cint}, Csize_t, Ptr{Cint}),
           tag, convert(Vector{Cint}, cornerTags), length(cornerTags), ierr)
-    ierr[] != 0 && error("gmshModelGeoMeshSetTransfiniteVolume returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -3415,7 +3415,7 @@ function setRecombine(dim, tag, angle = 45.)
     ccall((:gmshModelGeoMeshSetRecombine, gmsh.lib), Cvoid,
           (Cint, Cint, Cdouble, Ptr{Cint}),
           dim, tag, angle, ierr)
-    ierr[] != 0 && error("gmshModelGeoMeshSetRecombine returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -3430,7 +3430,7 @@ function setSmoothing(dim, tag, val)
     ccall((:gmshModelGeoMeshSetSmoothing, gmsh.lib), Cvoid,
           (Cint, Cint, Cint, Ptr{Cint}),
           dim, tag, val, ierr)
-    ierr[] != 0 && error("gmshModelGeoMeshSetSmoothing returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -3447,7 +3447,7 @@ function setReverse(dim, tag, val = true)
     ccall((:gmshModelGeoMeshSetReverse, gmsh.lib), Cvoid,
           (Cint, Cint, Cint, Ptr{Cint}),
           dim, tag, val, ierr)
-    ierr[] != 0 && error("gmshModelGeoMeshSetReverse returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -3462,7 +3462,7 @@ function setAlgorithm(dim, tag, val)
     ccall((:gmshModelGeoMeshSetAlgorithm, gmsh.lib), Cvoid,
           (Cint, Cint, Cint, Ptr{Cint}),
           dim, tag, val, ierr)
-    ierr[] != 0 && error("gmshModelGeoMeshSetAlgorithm returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -3478,7 +3478,7 @@ function setSizeFromBoundary(dim, tag, val)
     ccall((:gmshModelGeoMeshSetSizeFromBoundary, gmsh.lib), Cvoid,
           (Cint, Cint, Cint, Ptr{Cint}),
           dim, tag, val, ierr)
-    ierr[] != 0 && error("gmshModelGeoMeshSetSizeFromBoundary returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -3509,11 +3509,11 @@ Return an integer value.
 """
 function addPoint(x, y, z, meshSize = 0., tag = -1)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelOccAddPoint, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelOccAddPoint, gmsh.lib), Cint,
           (Cdouble, Cdouble, Cdouble, Cdouble, Cint, Ptr{Cint}),
           x, y, z, meshSize, tag, ierr)
-    ierr[] != 0 && error("gmshModelOccAddPoint returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -3527,11 +3527,11 @@ Return an integer value.
 """
 function addLine(startTag, endTag, tag = -1)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelOccAddLine, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelOccAddLine, gmsh.lib), Cint,
           (Cint, Cint, Cint, Ptr{Cint}),
           startTag, endTag, tag, ierr)
-    ierr[] != 0 && error("gmshModelOccAddLine returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -3545,11 +3545,11 @@ Return an integer value.
 """
 function addCircleArc(startTag, centerTag, endTag, tag = -1)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelOccAddCircleArc, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelOccAddCircleArc, gmsh.lib), Cint,
           (Cint, Cint, Cint, Cint, Ptr{Cint}),
           startTag, centerTag, endTag, tag, ierr)
-    ierr[] != 0 && error("gmshModelOccAddCircleArc returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -3564,11 +3564,11 @@ Return an integer value.
 """
 function addCircle(x, y, z, r, tag = -1, angle1 = 0., angle2 = 2*pi)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelOccAddCircle, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelOccAddCircle, gmsh.lib), Cint,
           (Cdouble, Cdouble, Cdouble, Cdouble, Cint, Cdouble, Cdouble, Ptr{Cint}),
           x, y, z, r, tag, angle1, angle2, ierr)
-    ierr[] != 0 && error("gmshModelOccAddCircle returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -3584,11 +3584,11 @@ Return an integer value.
 """
 function addEllipseArc(startTag, centerTag, majorTag, endTag, tag = -1)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelOccAddEllipseArc, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelOccAddEllipseArc, gmsh.lib), Cint,
           (Cint, Cint, Cint, Cint, Cint, Ptr{Cint}),
           startTag, centerTag, majorTag, endTag, tag, ierr)
-    ierr[] != 0 && error("gmshModelOccAddEllipseArc returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -3606,11 +3606,11 @@ Return an integer value.
 """
 function addEllipse(x, y, z, r1, r2, tag = -1, angle1 = 0., angle2 = 2*pi)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelOccAddEllipse, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelOccAddEllipse, gmsh.lib), Cint,
           (Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cint, Cdouble, Cdouble, Ptr{Cint}),
           x, y, z, r1, r2, tag, angle1, angle2, ierr)
-    ierr[] != 0 && error("gmshModelOccAddEllipse returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -3625,11 +3625,11 @@ Return an integer value.
 """
 function addSpline(pointTags, tag = -1)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelOccAddSpline, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelOccAddSpline, gmsh.lib), Cint,
           (Ptr{Cint}, Csize_t, Cint, Ptr{Cint}),
           convert(Vector{Cint}, pointTags), length(pointTags), tag, ierr)
-    ierr[] != 0 && error("gmshModelOccAddSpline returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -3645,11 +3645,11 @@ Return an integer value.
 """
 function addBSpline(pointTags, tag = -1, degree = 3, weights = Cdouble[], knots = Cdouble[], multiplicities = Cint[])
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelOccAddBSpline, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelOccAddBSpline, gmsh.lib), Cint,
           (Ptr{Cint}, Csize_t, Cint, Cint, Ptr{Cdouble}, Csize_t, Ptr{Cdouble}, Csize_t, Ptr{Cint}, Csize_t, Ptr{Cint}),
           convert(Vector{Cint}, pointTags), length(pointTags), tag, degree, convert(Vector{Cdouble}, weights), length(weights), convert(Vector{Cdouble}, knots), length(knots), convert(Vector{Cint}, multiplicities), length(multiplicities), ierr)
-    ierr[] != 0 && error("gmshModelOccAddBSpline returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -3663,11 +3663,11 @@ Return an integer value.
 """
 function addBezier(pointTags, tag = -1)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelOccAddBezier, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelOccAddBezier, gmsh.lib), Cint,
           (Ptr{Cint}, Csize_t, Cint, Ptr{Cint}),
           convert(Vector{Cint}, pointTags), length(pointTags), tag, ierr)
-    ierr[] != 0 && error("gmshModelOccAddBezier returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -3682,11 +3682,11 @@ Return an integer value.
 """
 function addWire(curveTags, tag = -1, checkClosed = false)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelOccAddWire, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelOccAddWire, gmsh.lib), Cint,
           (Ptr{Cint}, Csize_t, Cint, Cint, Ptr{Cint}),
           convert(Vector{Cint}, curveTags), length(curveTags), tag, checkClosed, ierr)
-    ierr[] != 0 && error("gmshModelOccAddWire returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -3702,11 +3702,11 @@ Return an integer value.
 """
 function addCurveLoop(curveTags, tag = -1)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelOccAddCurveLoop, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelOccAddCurveLoop, gmsh.lib), Cint,
           (Ptr{Cint}, Csize_t, Cint, Ptr{Cint}),
           convert(Vector{Cint}, curveTags), length(curveTags), tag, ierr)
-    ierr[] != 0 && error("gmshModelOccAddCurveLoop returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -3721,11 +3721,11 @@ Return an integer value.
 """
 function addRectangle(x, y, z, dx, dy, tag = -1, roundedRadius = 0.)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelOccAddRectangle, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelOccAddRectangle, gmsh.lib), Cint,
           (Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cint, Cdouble, Ptr{Cint}),
           x, y, z, dx, dy, tag, roundedRadius, ierr)
-    ierr[] != 0 && error("gmshModelOccAddRectangle returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -3739,11 +3739,11 @@ Return an integer value.
 """
 function addDisk(xc, yc, zc, rx, ry, tag = -1)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelOccAddDisk, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelOccAddDisk, gmsh.lib), Cint,
           (Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cint, Ptr{Cint}),
           xc, yc, zc, rx, ry, tag, ierr)
-    ierr[] != 0 && error("gmshModelOccAddDisk returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -3758,11 +3758,11 @@ Return an integer value.
 """
 function addPlaneSurface(wireTags, tag = -1)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelOccAddPlaneSurface, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelOccAddPlaneSurface, gmsh.lib), Cint,
           (Ptr{Cint}, Csize_t, Cint, Ptr{Cint}),
           convert(Vector{Cint}, wireTags), length(wireTags), tag, ierr)
-    ierr[] != 0 && error("gmshModelOccAddPlaneSurface returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -3777,11 +3777,11 @@ Return an integer value.
 """
 function addSurfaceFilling(wireTag, tag = -1, pointTags = Cint[])
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelOccAddSurfaceFilling, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelOccAddSurfaceFilling, gmsh.lib), Cint,
           (Cint, Cint, Ptr{Cint}, Csize_t, Ptr{Cint}),
           wireTag, tag, convert(Vector{Cint}, pointTags), length(pointTags), ierr)
-    ierr[] != 0 && error("gmshModelOccAddSurfaceFilling returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -3798,11 +3798,11 @@ Return an integer value.
 """
 function addBSplineFilling(wireTag, tag = -1, type = "")
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelOccAddBSplineFilling, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelOccAddBSplineFilling, gmsh.lib), Cint,
           (Cint, Cint, Ptr{Cchar}, Ptr{Cint}),
           wireTag, tag, type, ierr)
-    ierr[] != 0 && error("gmshModelOccAddBSplineFilling returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -3819,11 +3819,11 @@ Return an integer value.
 """
 function addBezierFilling(wireTag, tag = -1, type = "")
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelOccAddBezierFilling, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelOccAddBezierFilling, gmsh.lib), Cint,
           (Cint, Cint, Ptr{Cchar}, Ptr{Cint}),
           wireTag, tag, type, ierr)
-    ierr[] != 0 && error("gmshModelOccAddBezierFilling returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -3840,11 +3840,11 @@ Return an integer value.
 """
 function addBSplineSurface(pointTags, numPointsU, tag = -1, degreeU = 3, degreeV = 3, weights = Cdouble[], knotsU = Cdouble[], knotsV = Cdouble[], multiplicitiesU = Cint[], multiplicitiesV = Cint[])
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelOccAddBSplineSurface, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelOccAddBSplineSurface, gmsh.lib), Cint,
           (Ptr{Cint}, Csize_t, Cint, Cint, Cint, Cint, Ptr{Cdouble}, Csize_t, Ptr{Cdouble}, Csize_t, Ptr{Cdouble}, Csize_t, Ptr{Cint}, Csize_t, Ptr{Cint}, Csize_t, Ptr{Cint}),
           convert(Vector{Cint}, pointTags), length(pointTags), numPointsU, tag, degreeU, degreeV, convert(Vector{Cdouble}, weights), length(weights), convert(Vector{Cdouble}, knotsU), length(knotsU), convert(Vector{Cdouble}, knotsV), length(knotsV), convert(Vector{Cint}, multiplicitiesU), length(multiplicitiesU), convert(Vector{Cint}, multiplicitiesV), length(multiplicitiesV), ierr)
-    ierr[] != 0 && error("gmshModelOccAddBSplineSurface returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -3859,11 +3859,11 @@ Return an integer value.
 """
 function addBezierSurface(pointTags, numPointsU, tag = -1)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelOccAddBezierSurface, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelOccAddBezierSurface, gmsh.lib), Cint,
           (Ptr{Cint}, Csize_t, Cint, Cint, Ptr{Cint}),
           convert(Vector{Cint}, pointTags), length(pointTags), numPointsU, tag, ierr)
-    ierr[] != 0 && error("gmshModelOccAddBezierSurface returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -3879,11 +3879,11 @@ Return an integer value.
 """
 function addSurfaceLoop(surfaceTags, tag = -1, sewing = false)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelOccAddSurfaceLoop, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelOccAddSurfaceLoop, gmsh.lib), Cint,
           (Ptr{Cint}, Csize_t, Cint, Cint, Ptr{Cint}),
           convert(Vector{Cint}, surfaceTags), length(surfaceTags), tag, sewing, ierr)
-    ierr[] != 0 && error("gmshModelOccAddSurfaceLoop returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -3898,11 +3898,11 @@ Return an integer value.
 """
 function addVolume(shellTags, tag = -1)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelOccAddVolume, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelOccAddVolume, gmsh.lib), Cint,
           (Ptr{Cint}, Csize_t, Cint, Ptr{Cint}),
           convert(Vector{Cint}, shellTags), length(shellTags), tag, ierr)
-    ierr[] != 0 && error("gmshModelOccAddVolume returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -3918,11 +3918,11 @@ Return an integer value.
 """
 function addSphere(xc, yc, zc, radius, tag = -1, angle1 = -pi/2, angle2 = pi/2, angle3 = 2*pi)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelOccAddSphere, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelOccAddSphere, gmsh.lib), Cint,
           (Cdouble, Cdouble, Cdouble, Cdouble, Cint, Cdouble, Cdouble, Cdouble, Ptr{Cint}),
           xc, yc, zc, radius, tag, angle1, angle2, angle3, ierr)
-    ierr[] != 0 && error("gmshModelOccAddSphere returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -3936,11 +3936,11 @@ Return an integer value.
 """
 function addBox(x, y, z, dx, dy, dz, tag = -1)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelOccAddBox, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelOccAddBox, gmsh.lib), Cint,
           (Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cint, Ptr{Cint}),
           x, y, z, dx, dy, dz, tag, ierr)
-    ierr[] != 0 && error("gmshModelOccAddBox returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -3956,11 +3956,11 @@ Return an integer value.
 """
 function addCylinder(x, y, z, dx, dy, dz, r, tag = -1, angle = 2*pi)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelOccAddCylinder, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelOccAddCylinder, gmsh.lib), Cint,
           (Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cint, Cdouble, Ptr{Cint}),
           x, y, z, dx, dy, dz, r, tag, angle, ierr)
-    ierr[] != 0 && error("gmshModelOccAddCylinder returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -3977,11 +3977,11 @@ Return an integer value.
 """
 function addCone(x, y, z, dx, dy, dz, r1, r2, tag = -1, angle = 2*pi)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelOccAddCone, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelOccAddCone, gmsh.lib), Cint,
           (Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cint, Cdouble, Ptr{Cint}),
           x, y, z, dx, dy, dz, r1, r2, tag, angle, ierr)
-    ierr[] != 0 && error("gmshModelOccAddCone returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -3997,11 +3997,11 @@ Return an integer value.
 """
 function addWedge(x, y, z, dx, dy, dz, tag = -1, ltx = 0.)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelOccAddWedge, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelOccAddWedge, gmsh.lib), Cint,
           (Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cint, Cdouble, Ptr{Cint}),
           x, y, z, dx, dy, dz, tag, ltx, ierr)
-    ierr[] != 0 && error("gmshModelOccAddWedge returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -4016,11 +4016,11 @@ Return an integer value.
 """
 function addTorus(x, y, z, r1, r2, tag = -1, angle = 2*pi)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelOccAddTorus, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelOccAddTorus, gmsh.lib), Cint,
           (Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cint, Cdouble, Ptr{Cint}),
           x, y, z, r1, r2, tag, angle, ierr)
-    ierr[] != 0 && error("gmshModelOccAddTorus returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -4042,7 +4042,7 @@ function addThruSections(wireTags, tag = -1, makeSolid = true, makeRuled = false
     ccall((:gmshModelOccAddThruSections, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Ptr{Ptr{Cint}}, Ptr{Csize_t}, Cint, Cint, Cint, Cint, Ptr{Cint}),
           convert(Vector{Cint}, wireTags), length(wireTags), api_outDimTags_, api_outDimTags_n_, tag, makeSolid, makeRuled, maxDegree, ierr)
-    ierr[] != 0 && error("gmshModelOccAddThruSections returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     tmp_api_outDimTags_ = unsafe_wrap(Array, api_outDimTags_[], api_outDimTags_n_[], own=true)
     outDimTags = [ (tmp_api_outDimTags_[i], tmp_api_outDimTags_[i+1]) for i in 1:2:length(tmp_api_outDimTags_) ]
     return outDimTags
@@ -4066,7 +4066,7 @@ function addThickSolid(volumeTag, excludeSurfaceTags, offset, tag = -1)
     ccall((:gmshModelOccAddThickSolid, gmsh.lib), Cvoid,
           (Cint, Ptr{Cint}, Csize_t, Cdouble, Ptr{Ptr{Cint}}, Ptr{Csize_t}, Cint, Ptr{Cint}),
           volumeTag, convert(Vector{Cint}, excludeSurfaceTags), length(excludeSurfaceTags), offset, api_outDimTags_, api_outDimTags_n_, tag, ierr)
-    ierr[] != 0 && error("gmshModelOccAddThickSolid returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     tmp_api_outDimTags_ = unsafe_wrap(Array, api_outDimTags_[], api_outDimTags_n_[], own=true)
     outDimTags = [ (tmp_api_outDimTags_[i], tmp_api_outDimTags_[i+1]) for i in 1:2:length(tmp_api_outDimTags_) ]
     return outDimTags
@@ -4092,7 +4092,7 @@ function extrude(dimTags, dx, dy, dz, numElements = Cint[], heights = Cdouble[],
     ccall((:gmshModelOccExtrude, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Cdouble, Cdouble, Cdouble, Ptr{Ptr{Cint}}, Ptr{Csize_t}, Ptr{Cint}, Csize_t, Ptr{Cdouble}, Csize_t, Cint, Ptr{Cint}),
           api_dimTags_, api_dimTags_n_, dx, dy, dz, api_outDimTags_, api_outDimTags_n_, convert(Vector{Cint}, numElements), length(numElements), convert(Vector{Cdouble}, heights), length(heights), recombine, ierr)
-    ierr[] != 0 && error("gmshModelOccExtrude returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     tmp_api_outDimTags_ = unsafe_wrap(Array, api_outDimTags_[], api_outDimTags_n_[], own=true)
     outDimTags = [ (tmp_api_outDimTags_[i], tmp_api_outDimTags_[i+1]) for i in 1:2:length(tmp_api_outDimTags_) ]
     return outDimTags
@@ -4120,7 +4120,7 @@ function revolve(dimTags, x, y, z, ax, ay, az, angle, numElements = Cint[], heig
     ccall((:gmshModelOccRevolve, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Ptr{Ptr{Cint}}, Ptr{Csize_t}, Ptr{Cint}, Csize_t, Ptr{Cdouble}, Csize_t, Cint, Ptr{Cint}),
           api_dimTags_, api_dimTags_n_, x, y, z, ax, ay, az, angle, api_outDimTags_, api_outDimTags_n_, convert(Vector{Cint}, numElements), length(numElements), convert(Vector{Cdouble}, heights), length(heights), recombine, ierr)
-    ierr[] != 0 && error("gmshModelOccRevolve returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     tmp_api_outDimTags_ = unsafe_wrap(Array, api_outDimTags_[], api_outDimTags_n_[], own=true)
     outDimTags = [ (tmp_api_outDimTags_[i], tmp_api_outDimTags_[i+1]) for i in 1:2:length(tmp_api_outDimTags_) ]
     return outDimTags
@@ -4143,7 +4143,7 @@ function addPipe(dimTags, wireTag)
     ccall((:gmshModelOccAddPipe, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Cint, Ptr{Ptr{Cint}}, Ptr{Csize_t}, Ptr{Cint}),
           api_dimTags_, api_dimTags_n_, wireTag, api_outDimTags_, api_outDimTags_n_, ierr)
-    ierr[] != 0 && error("gmshModelOccAddPipe returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     tmp_api_outDimTags_ = unsafe_wrap(Array, api_outDimTags_[], api_outDimTags_n_[], own=true)
     outDimTags = [ (tmp_api_outDimTags_[i], tmp_api_outDimTags_[i+1]) for i in 1:2:length(tmp_api_outDimTags_) ]
     return outDimTags
@@ -4167,7 +4167,7 @@ function fillet(volumeTags, curveTags, radii, removeVolume = true)
     ccall((:gmshModelOccFillet, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Ptr{Cint}, Csize_t, Ptr{Cdouble}, Csize_t, Ptr{Ptr{Cint}}, Ptr{Csize_t}, Cint, Ptr{Cint}),
           convert(Vector{Cint}, volumeTags), length(volumeTags), convert(Vector{Cint}, curveTags), length(curveTags), convert(Vector{Cdouble}, radii), length(radii), api_outDimTags_, api_outDimTags_n_, removeVolume, ierr)
-    ierr[] != 0 && error("gmshModelOccFillet returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     tmp_api_outDimTags_ = unsafe_wrap(Array, api_outDimTags_[], api_outDimTags_n_[], own=true)
     outDimTags = [ (tmp_api_outDimTags_[i], tmp_api_outDimTags_[i+1]) for i in 1:2:length(tmp_api_outDimTags_) ]
     return outDimTags
@@ -4193,7 +4193,7 @@ function chamfer(volumeTags, curveTags, surfaceTags, distances, removeVolume = t
     ccall((:gmshModelOccChamfer, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Ptr{Cint}, Csize_t, Ptr{Cint}, Csize_t, Ptr{Cdouble}, Csize_t, Ptr{Ptr{Cint}}, Ptr{Csize_t}, Cint, Ptr{Cint}),
           convert(Vector{Cint}, volumeTags), length(volumeTags), convert(Vector{Cint}, curveTags), length(curveTags), convert(Vector{Cint}, surfaceTags), length(surfaceTags), convert(Vector{Cdouble}, distances), length(distances), api_outDimTags_, api_outDimTags_n_, removeVolume, ierr)
-    ierr[] != 0 && error("gmshModelOccChamfer returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     tmp_api_outDimTags_ = unsafe_wrap(Array, api_outDimTags_[], api_outDimTags_n_[], own=true)
     outDimTags = [ (tmp_api_outDimTags_[i], tmp_api_outDimTags_[i+1]) for i in 1:2:length(tmp_api_outDimTags_) ]
     return outDimTags
@@ -4224,7 +4224,7 @@ function fuse(objectDimTags, toolDimTags, tag = -1, removeObject = true, removeT
     ccall((:gmshModelOccFuse, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Ptr{Cint}, Csize_t, Ptr{Ptr{Cint}}, Ptr{Csize_t}, Ptr{Ptr{Ptr{Cint}}}, Ptr{Ptr{Csize_t}}, Ptr{Csize_t}, Cint, Cint, Cint, Ptr{Cint}),
           api_objectDimTags_, api_objectDimTags_n_, api_toolDimTags_, api_toolDimTags_n_, api_outDimTags_, api_outDimTags_n_, api_outDimTagsMap_, api_outDimTagsMap_n_, api_outDimTagsMap_nn_, tag, removeObject, removeTool, ierr)
-    ierr[] != 0 && error("gmshModelOccFuse returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     tmp_api_outDimTags_ = unsafe_wrap(Array, api_outDimTags_[], api_outDimTags_n_[], own=true)
     outDimTags = [ (tmp_api_outDimTags_[i], tmp_api_outDimTags_[i+1]) for i in 1:2:length(tmp_api_outDimTags_) ]
     tmp_api_outDimTagsMap_ = unsafe_wrap(Array, api_outDimTagsMap_[], api_outDimTagsMap_nn_[], own=true)
@@ -4263,7 +4263,7 @@ function intersect(objectDimTags, toolDimTags, tag = -1, removeObject = true, re
     ccall((:gmshModelOccIntersect, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Ptr{Cint}, Csize_t, Ptr{Ptr{Cint}}, Ptr{Csize_t}, Ptr{Ptr{Ptr{Cint}}}, Ptr{Ptr{Csize_t}}, Ptr{Csize_t}, Cint, Cint, Cint, Ptr{Cint}),
           api_objectDimTags_, api_objectDimTags_n_, api_toolDimTags_, api_toolDimTags_n_, api_outDimTags_, api_outDimTags_n_, api_outDimTagsMap_, api_outDimTagsMap_n_, api_outDimTagsMap_nn_, tag, removeObject, removeTool, ierr)
-    ierr[] != 0 && error("gmshModelOccIntersect returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     tmp_api_outDimTags_ = unsafe_wrap(Array, api_outDimTags_[], api_outDimTags_n_[], own=true)
     outDimTags = [ (tmp_api_outDimTags_[i], tmp_api_outDimTags_[i+1]) for i in 1:2:length(tmp_api_outDimTags_) ]
     tmp_api_outDimTagsMap_ = unsafe_wrap(Array, api_outDimTagsMap_[], api_outDimTagsMap_nn_[], own=true)
@@ -4302,7 +4302,7 @@ function cut(objectDimTags, toolDimTags, tag = -1, removeObject = true, removeTo
     ccall((:gmshModelOccCut, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Ptr{Cint}, Csize_t, Ptr{Ptr{Cint}}, Ptr{Csize_t}, Ptr{Ptr{Ptr{Cint}}}, Ptr{Ptr{Csize_t}}, Ptr{Csize_t}, Cint, Cint, Cint, Ptr{Cint}),
           api_objectDimTags_, api_objectDimTags_n_, api_toolDimTags_, api_toolDimTags_n_, api_outDimTags_, api_outDimTags_n_, api_outDimTagsMap_, api_outDimTagsMap_n_, api_outDimTagsMap_nn_, tag, removeObject, removeTool, ierr)
-    ierr[] != 0 && error("gmshModelOccCut returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     tmp_api_outDimTags_ = unsafe_wrap(Array, api_outDimTags_[], api_outDimTags_n_[], own=true)
     outDimTags = [ (tmp_api_outDimTags_[i], tmp_api_outDimTags_[i+1]) for i in 1:2:length(tmp_api_outDimTags_) ]
     tmp_api_outDimTagsMap_ = unsafe_wrap(Array, api_outDimTagsMap_[], api_outDimTagsMap_nn_[], own=true)
@@ -4341,7 +4341,7 @@ function fragment(objectDimTags, toolDimTags, tag = -1, removeObject = true, rem
     ccall((:gmshModelOccFragment, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Ptr{Cint}, Csize_t, Ptr{Ptr{Cint}}, Ptr{Csize_t}, Ptr{Ptr{Ptr{Cint}}}, Ptr{Ptr{Csize_t}}, Ptr{Csize_t}, Cint, Cint, Cint, Ptr{Cint}),
           api_objectDimTags_, api_objectDimTags_n_, api_toolDimTags_, api_toolDimTags_n_, api_outDimTags_, api_outDimTags_n_, api_outDimTagsMap_, api_outDimTagsMap_n_, api_outDimTagsMap_nn_, tag, removeObject, removeTool, ierr)
-    ierr[] != 0 && error("gmshModelOccFragment returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     tmp_api_outDimTags_ = unsafe_wrap(Array, api_outDimTags_[], api_outDimTags_n_[], own=true)
     outDimTags = [ (tmp_api_outDimTags_[i], tmp_api_outDimTags_[i+1]) for i in 1:2:length(tmp_api_outDimTags_) ]
     tmp_api_outDimTagsMap_ = unsafe_wrap(Array, api_outDimTagsMap_[], api_outDimTagsMap_nn_[], own=true)
@@ -4367,7 +4367,7 @@ function translate(dimTags, dx, dy, dz)
     ccall((:gmshModelOccTranslate, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Cdouble, Cdouble, Cdouble, Ptr{Cint}),
           api_dimTags_, api_dimTags_n_, dx, dy, dz, ierr)
-    ierr[] != 0 && error("gmshModelOccTranslate returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -4385,7 +4385,7 @@ function rotate(dimTags, x, y, z, ax, ay, az, angle)
     ccall((:gmshModelOccRotate, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Ptr{Cint}),
           api_dimTags_, api_dimTags_n_, x, y, z, ax, ay, az, angle, ierr)
-    ierr[] != 0 && error("gmshModelOccRotate returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -4403,7 +4403,7 @@ function dilate(dimTags, x, y, z, a, b, c)
     ccall((:gmshModelOccDilate, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Ptr{Cint}),
           api_dimTags_, api_dimTags_n_, x, y, z, a, b, c, ierr)
-    ierr[] != 0 && error("gmshModelOccDilate returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -4420,7 +4420,7 @@ function mirror(dimTags, a, b, c, d)
     ccall((:gmshModelOccMirror, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Cdouble, Cdouble, Cdouble, Cdouble, Ptr{Cint}),
           api_dimTags_, api_dimTags_n_, a, b, c, d, ierr)
-    ierr[] != 0 && error("gmshModelOccMirror returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -4438,7 +4438,7 @@ function symmetrize(dimTags, a, b, c, d)
     ccall((:gmshModelOccSymmetrize, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Cdouble, Cdouble, Cdouble, Cdouble, Ptr{Cint}),
           api_dimTags_, api_dimTags_n_, a, b, c, d, ierr)
-    ierr[] != 0 && error("gmshModelOccSymmetrize returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -4456,7 +4456,7 @@ function affineTransform(dimTags, a)
     ccall((:gmshModelOccAffineTransform, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Ptr{Cdouble}, Csize_t, Ptr{Cint}),
           api_dimTags_, api_dimTags_n_, convert(Vector{Cdouble}, a), length(a), ierr)
-    ierr[] != 0 && error("gmshModelOccAffineTransform returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -4476,7 +4476,7 @@ function copy(dimTags)
     ccall((:gmshModelOccCopy, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Ptr{Ptr{Cint}}, Ptr{Csize_t}, Ptr{Cint}),
           api_dimTags_, api_dimTags_n_, api_outDimTags_, api_outDimTags_n_, ierr)
-    ierr[] != 0 && error("gmshModelOccCopy returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     tmp_api_outDimTags_ = unsafe_wrap(Array, api_outDimTags_[], api_outDimTags_n_[], own=true)
     outDimTags = [ (tmp_api_outDimTags_[i], tmp_api_outDimTags_[i+1]) for i in 1:2:length(tmp_api_outDimTags_) ]
     return outDimTags
@@ -4495,7 +4495,7 @@ function remove(dimTags, recursive = false)
     ccall((:gmshModelOccRemove, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Cint, Ptr{Cint}),
           api_dimTags_, api_dimTags_n_, recursive, ierr)
-    ierr[] != 0 && error("gmshModelOccRemove returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -4511,7 +4511,7 @@ function removeAllDuplicates()
     ccall((:gmshModelOccRemoveAllDuplicates, gmsh.lib), Cvoid,
           (Ptr{Cint},),
           ierr)
-    ierr[] != 0 && error("gmshModelOccRemoveAllDuplicates returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -4533,7 +4533,7 @@ function healShapes(dimTags = Tuple{Cint,Cint}[], tolerance = 1e-8, fixDegenerat
     ccall((:gmshModelOccHealShapes, gmsh.lib), Cvoid,
           (Ptr{Ptr{Cint}}, Ptr{Csize_t}, Ptr{Cint}, Csize_t, Cdouble, Cint, Cint, Cint, Cint, Cint, Ptr{Cint}),
           api_outDimTags_, api_outDimTags_n_, api_dimTags_, api_dimTags_n_, tolerance, fixDegenerated, fixSmallEdges, fixSmallFaces, sewFaces, makeSolids, ierr)
-    ierr[] != 0 && error("gmshModelOccHealShapes returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     tmp_api_outDimTags_ = unsafe_wrap(Array, api_outDimTags_[], api_outDimTags_n_[], own=true)
     outDimTags = [ (tmp_api_outDimTags_[i], tmp_api_outDimTags_[i+1]) for i in 1:2:length(tmp_api_outDimTags_) ]
     return outDimTags
@@ -4557,7 +4557,7 @@ function importShapes(fileName, highestDimOnly = true, format = "")
     ccall((:gmshModelOccImportShapes, gmsh.lib), Cvoid,
           (Ptr{Cchar}, Ptr{Ptr{Cint}}, Ptr{Csize_t}, Cint, Ptr{Cchar}, Ptr{Cint}),
           fileName, api_outDimTags_, api_outDimTags_n_, highestDimOnly, format, ierr)
-    ierr[] != 0 && error("gmshModelOccImportShapes returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     tmp_api_outDimTags_ = unsafe_wrap(Array, api_outDimTags_[], api_outDimTags_n_[], own=true)
     outDimTags = [ (tmp_api_outDimTags_[i], tmp_api_outDimTags_[i+1]) for i in 1:2:length(tmp_api_outDimTags_) ]
     return outDimTags
@@ -4579,7 +4579,7 @@ function getEntities(dim = -1)
     ccall((:gmshModelOccGetEntities, gmsh.lib), Cvoid,
           (Ptr{Ptr{Cint}}, Ptr{Csize_t}, Cint, Ptr{Cint}),
           api_dimTags_, api_dimTags_n_, dim, ierr)
-    ierr[] != 0 && error("gmshModelOccGetEntities returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     tmp_api_dimTags_ = unsafe_wrap(Array, api_dimTags_[], api_dimTags_n_[], own=true)
     dimTags = [ (tmp_api_dimTags_[i], tmp_api_dimTags_[i+1]) for i in 1:2:length(tmp_api_dimTags_) ]
     return dimTags
@@ -4601,7 +4601,7 @@ function getEntitiesInBoundingBox(xmin, ymin, zmin, xmax, ymax, zmax, dim = -1)
     ccall((:gmshModelOccGetEntitiesInBoundingBox, gmsh.lib), Cvoid,
           (Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Ptr{Ptr{Cint}}, Ptr{Csize_t}, Cint, Ptr{Cint}),
           xmin, ymin, zmin, xmax, ymax, zmax, api_tags_, api_tags_n_, dim, ierr)
-    ierr[] != 0 && error("gmshModelOccGetEntitiesInBoundingBox returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     tmp_api_tags_ = unsafe_wrap(Array, api_tags_[], api_tags_n_[], own=true)
     tags = [ (tmp_api_tags_[i], tmp_api_tags_[i+1]) for i in 1:2:length(tmp_api_tags_) ]
     return tags
@@ -4626,7 +4626,7 @@ function getBoundingBox(dim, tag)
     ccall((:gmshModelOccGetBoundingBox, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cint}),
           dim, tag, api_xmin_, api_ymin_, api_zmin_, api_xmax_, api_ymax_, api_zmax_, ierr)
-    ierr[] != 0 && error("gmshModelOccGetBoundingBox returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return api_xmin_[], api_ymin_[], api_zmin_[], api_xmax_[], api_ymax_[], api_zmax_[]
 end
 
@@ -4643,7 +4643,7 @@ function getMass(dim, tag)
     ccall((:gmshModelOccGetMass, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Cdouble}, Ptr{Cint}),
           dim, tag, api_mass_, ierr)
-    ierr[] != 0 && error("gmshModelOccGetMass returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return api_mass_[]
 end
 
@@ -4663,7 +4663,7 @@ function getCenterOfMass(dim, tag)
     ccall((:gmshModelOccGetCenterOfMass, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cint}),
           dim, tag, api_x_, api_y_, api_z_, ierr)
-    ierr[] != 0 && error("gmshModelOccGetCenterOfMass returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return api_x_[], api_y_[], api_z_[]
 end
 
@@ -4682,7 +4682,7 @@ function getMatrixOfInertia(dim, tag)
     ccall((:gmshModelOccGetMatrixOfInertia, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Ptr{Cint}),
           dim, tag, api_mat_, api_mat_n_, ierr)
-    ierr[] != 0 && error("gmshModelOccGetMatrixOfInertia returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     mat = unsafe_wrap(Array, api_mat_[], api_mat_n_[], own=true)
     return mat
 end
@@ -4697,11 +4697,11 @@ Return an integer value.
 """
 function getMaxTag(dim)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshModelOccGetMaxTag, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshModelOccGetMaxTag, gmsh.lib), Cint,
           (Cint, Ptr{Cint}),
           dim, ierr)
-    ierr[] != 0 && error("gmshModelOccGetMaxTag returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -4715,7 +4715,7 @@ function setMaxTag(dim, maxTag)
     ccall((:gmshModelOccSetMaxTag, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Cint}),
           dim, maxTag, ierr)
-    ierr[] != 0 && error("gmshModelOccSetMaxTag returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -4731,7 +4731,7 @@ function synchronize()
     ccall((:gmshModelOccSynchronize, gmsh.lib), Cvoid,
           (Ptr{Cint},),
           ierr)
-    ierr[] != 0 && error("gmshModelOccSynchronize returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -4757,7 +4757,7 @@ function setSize(dimTags, size)
     ccall((:gmshModelOccMeshSetSize, gmsh.lib), Cvoid,
           (Ptr{Cint}, Csize_t, Cdouble, Ptr{Cint}),
           api_dimTags_, api_dimTags_n_, size, ierr)
-    ierr[] != 0 && error("gmshModelOccMeshSetSize returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -4787,11 +4787,11 @@ Return an integer value.
 """
 function add(name, tag = -1)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshViewAdd, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshViewAdd, gmsh.lib), Cint,
           (Ptr{Cchar}, Cint, Ptr{Cint}),
           name, tag, ierr)
-    ierr[] != 0 && error("gmshViewAdd returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -4804,7 +4804,7 @@ function remove(tag)
     ccall((:gmshViewRemove, gmsh.lib), Cvoid,
           (Cint, Ptr{Cint}),
           tag, ierr)
-    ierr[] != 0 && error("gmshViewRemove returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -4819,11 +4819,11 @@ Return an integer value.
 """
 function getIndex(tag)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshViewGetIndex, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshViewGetIndex, gmsh.lib), Cint,
           (Cint, Ptr{Cint}),
           tag, ierr)
-    ierr[] != 0 && error("gmshViewGetIndex returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -4840,7 +4840,7 @@ function getTags()
     ccall((:gmshViewGetTags, gmsh.lib), Cvoid,
           (Ptr{Ptr{Cint}}, Ptr{Csize_t}, Ptr{Cint}),
           api_tags_, api_tags_n_, ierr)
-    ierr[] != 0 && error("gmshViewGetTags returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     tags = unsafe_wrap(Array, api_tags_[], api_tags_n_[], own=true)
     return tags
 end
@@ -4867,7 +4867,7 @@ function addModelData(tag, step, modelName, dataType, tags, data, time = 0., num
     ccall((:gmshViewAddModelData, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Cchar}, Ptr{Cchar}, Ptr{Csize_t}, Csize_t, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Csize_t, Cdouble, Cint, Cint, Ptr{Cint}),
           tag, step, modelName, dataType, convert(Vector{Csize_t}, tags), length(tags), convert(Vector{Vector{Cdouble}},data), api_data_n_, length(data), time, numComponents, partition, ierr)
-    ierr[] != 0 && error("gmshViewAddModelData returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -4885,7 +4885,7 @@ function addHomogeneousModelData(tag, step, modelName, dataType, tags, data, tim
     ccall((:gmshViewAddHomogeneousModelData, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Cchar}, Ptr{Cchar}, Ptr{Csize_t}, Csize_t, Ptr{Cdouble}, Csize_t, Cdouble, Cint, Cint, Ptr{Cint}),
           tag, step, modelName, dataType, convert(Vector{Csize_t}, tags), length(tags), convert(Vector{Cdouble}, data), length(data), time, numComponents, partition, ierr)
-    ierr[] != 0 && error("gmshViewAddHomogeneousModelData returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -4911,7 +4911,7 @@ function getModelData(tag, step)
     ccall((:gmshViewGetModelData, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Ptr{Cchar}}, Ptr{Ptr{Csize_t}}, Ptr{Csize_t}, Ptr{Ptr{Ptr{Cdouble}}}, Ptr{Ptr{Csize_t}}, Ptr{Csize_t}, Ptr{Cdouble}, Ptr{Cint}, Ptr{Cint}),
           tag, step, api_dataType_, api_tags_, api_tags_n_, api_data_, api_data_n_, api_data_nn_, api_time_, api_numComponents_, ierr)
-    ierr[] != 0 && error("gmshViewGetModelData returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     dataType = unsafe_string(api_dataType_[])
     tags = unsafe_wrap(Array, api_tags_[], api_tags_n_[], own=true)
     tmp_api_data_ = unsafe_wrap(Array, api_data_[], api_data_nn_[], own=true)
@@ -4942,7 +4942,7 @@ function getHomogeneousModelData(tag, step)
     ccall((:gmshViewGetHomogeneousModelData, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Ptr{Cchar}}, Ptr{Ptr{Csize_t}}, Ptr{Csize_t}, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Ptr{Cdouble}, Ptr{Cint}, Ptr{Cint}),
           tag, step, api_dataType_, api_tags_, api_tags_n_, api_data_, api_data_n_, api_time_, api_numComponents_, ierr)
-    ierr[] != 0 && error("gmshViewGetHomogeneousModelData returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     dataType = unsafe_string(api_dataType_[])
     tags = unsafe_wrap(Array, api_tags_[], api_tags_n_[], own=true)
     data = unsafe_wrap(Array, api_data_[], api_data_n_[], own=true)
@@ -4962,7 +4962,7 @@ function addListData(tag, dataType, numEle, data)
     ccall((:gmshViewAddListData, gmsh.lib), Cvoid,
           (Cint, Ptr{Cchar}, Cint, Ptr{Cdouble}, Csize_t, Ptr{Cint}),
           tag, dataType, numEle, convert(Vector{Cdouble}, data), length(data), ierr)
-    ierr[] != 0 && error("gmshViewAddListData returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -4987,7 +4987,7 @@ function getListData(tag)
     ccall((:gmshViewGetListData, gmsh.lib), Cvoid,
           (Cint, Ptr{Ptr{Ptr{Cchar}}}, Ptr{Csize_t}, Ptr{Ptr{Cint}}, Ptr{Csize_t}, Ptr{Ptr{Ptr{Cdouble}}}, Ptr{Ptr{Csize_t}}, Ptr{Csize_t}, Ptr{Cint}),
           tag, api_dataType_, api_dataType_n_, api_numElements_, api_numElements_n_, api_data_, api_data_n_, api_data_nn_, ierr)
-    ierr[] != 0 && error("gmshViewGetListData returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     tmp_api_dataType_ = unsafe_wrap(Array, api_dataType_[], api_dataType_n_[], own=true)
     dataType = [unsafe_string(tmp_api_dataType_[i]) for i in 1:length(tmp_api_dataType_) ]
     numElements = unsafe_wrap(Array, api_numElements_[], api_numElements_n_[], own=true)
@@ -5011,7 +5011,7 @@ function addListDataString(tag, coord, data, style = [])
     ccall((:gmshViewAddListDataString, gmsh.lib), Cvoid,
           (Cint, Ptr{Cdouble}, Csize_t, Ptr{Ptr{Cchar}}, Csize_t, Ptr{Ptr{Cchar}}, Csize_t, Ptr{Cint}),
           tag, convert(Vector{Cdouble}, coord), length(coord), data, length(data), style, length(style), ierr)
-    ierr[] != 0 && error("gmshViewAddListDataString returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -5035,7 +5035,7 @@ function getListDataStrings(tag, dim)
     ccall((:gmshViewGetListDataStrings, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Ptr{Ptr{Ptr{Cchar}}}, Ptr{Csize_t}, Ptr{Ptr{Ptr{Cchar}}}, Ptr{Csize_t}, Ptr{Cint}),
           tag, dim, api_coord_, api_coord_n_, api_data_, api_data_n_, api_style_, api_style_n_, ierr)
-    ierr[] != 0 && error("gmshViewGetListDataStrings returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     coord = unsafe_wrap(Array, api_coord_[], api_coord_n_[], own=true)
     tmp_api_data_ = unsafe_wrap(Array, api_data_[], api_data_n_[], own=true)
     data = [unsafe_string(tmp_api_data_[i]) for i in 1:length(tmp_api_data_) ]
@@ -5056,11 +5056,11 @@ Return an integer value.
 """
 function addAlias(refTag, copyOptions = false, tag = -1)
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshViewAddAlias, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshViewAddAlias, gmsh.lib), Cint,
           (Cint, Cint, Cint, Ptr{Cint}),
           refTag, copyOptions, tag, ierr)
-    ierr[] != 0 && error("gmshViewAddAlias returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -5073,7 +5073,7 @@ function copyOptions(refTag, tag)
     ccall((:gmshViewCopyOptions, gmsh.lib), Cvoid,
           (Cint, Cint, Ptr{Cint}),
           refTag, tag, ierr)
-    ierr[] != 0 && error("gmshViewCopyOptions returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -5090,7 +5090,7 @@ function combine(what, how, remove = true, copyOptions = true)
     ccall((:gmshViewCombine, gmsh.lib), Cvoid,
           (Ptr{Cchar}, Ptr{Cchar}, Cint, Cint, Ptr{Cint}),
           what, how, remove, copyOptions, ierr)
-    ierr[] != 0 && error("gmshViewCombine returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -5114,7 +5114,7 @@ function probe(tag, x, y, z, step = -1, numComp = -1, gradient = false, toleranc
     ccall((:gmshViewProbe, gmsh.lib), Cvoid,
           (Cint, Cdouble, Cdouble, Cdouble, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Cint, Cint, Cint, Cdouble, Ptr{Cdouble}, Csize_t, Ptr{Cdouble}, Csize_t, Ptr{Cdouble}, Csize_t, Ptr{Cint}),
           tag, x, y, z, api_value_, api_value_n_, step, numComp, gradient, tolerance, convert(Vector{Cdouble}, xElemCoord), length(xElemCoord), convert(Vector{Cdouble}, yElemCoord), length(yElemCoord), convert(Vector{Cdouble}, zElemCoord), length(zElemCoord), ierr)
-    ierr[] != 0 && error("gmshViewProbe returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     value = unsafe_wrap(Array, api_value_[], api_value_n_[], own=true)
     return value
 end
@@ -5130,7 +5130,7 @@ function write(tag, fileName, append = false)
     ccall((:gmshViewWrite, gmsh.lib), Cvoid,
           (Cint, Ptr{Cchar}, Cint, Ptr{Cint}),
           tag, fileName, append, ierr)
-    ierr[] != 0 && error("gmshViewWrite returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -5155,7 +5155,7 @@ function setNumber(name, option, value)
     ccall((:gmshPluginSetNumber, gmsh.lib), Cvoid,
           (Ptr{Cchar}, Ptr{Cchar}, Cdouble, Ptr{Cint}),
           name, option, value, ierr)
-    ierr[] != 0 && error("gmshPluginSetNumber returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -5169,7 +5169,7 @@ function setString(name, option, value)
     ccall((:gmshPluginSetString, gmsh.lib), Cvoid,
           (Ptr{Cchar}, Ptr{Cchar}, Ptr{Cchar}, Ptr{Cint}),
           name, option, value, ierr)
-    ierr[] != 0 && error("gmshPluginSetString returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -5183,7 +5183,7 @@ function run(name)
     ccall((:gmshPluginRun, gmsh.lib), Cvoid,
           (Ptr{Cchar}, Ptr{Cint}),
           name, ierr)
-    ierr[] != 0 && error("gmshPluginRun returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -5208,7 +5208,7 @@ function draw()
     ccall((:gmshGraphicsDraw, gmsh.lib), Cvoid,
           (Ptr{Cint},),
           ierr)
-    ierr[] != 0 && error("gmshGraphicsDraw returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -5233,7 +5233,7 @@ function initialize()
     ccall((:gmshFltkInitialize, gmsh.lib), Cvoid,
           (Ptr{Cint},),
           ierr)
-    ierr[] != 0 && error("gmshFltkInitialize returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -5249,7 +5249,7 @@ function wait(time = -1.)
     ccall((:gmshFltkWait, gmsh.lib), Cvoid,
           (Cdouble, Ptr{Cint}),
           time, ierr)
-    ierr[] != 0 && error("gmshFltkWait returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -5266,7 +5266,7 @@ function update()
     ccall((:gmshFltkUpdate, gmsh.lib), Cvoid,
           (Ptr{Cint},),
           ierr)
-    ierr[] != 0 && error("gmshFltkUpdate returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -5281,7 +5281,7 @@ function awake(action = "")
     ccall((:gmshFltkAwake, gmsh.lib), Cvoid,
           (Ptr{Cchar}, Ptr{Cint}),
           action, ierr)
-    ierr[] != 0 && error("gmshFltkAwake returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -5295,7 +5295,7 @@ function lock()
     ccall((:gmshFltkLock, gmsh.lib), Cvoid,
           (Ptr{Cint},),
           ierr)
-    ierr[] != 0 && error("gmshFltkLock returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -5309,7 +5309,7 @@ function unlock()
     ccall((:gmshFltkUnlock, gmsh.lib), Cvoid,
           (Ptr{Cint},),
           ierr)
-    ierr[] != 0 && error("gmshFltkUnlock returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -5325,7 +5325,7 @@ function run()
     ccall((:gmshFltkRun, gmsh.lib), Cvoid,
           (Ptr{Cint},),
           ierr)
-    ierr[] != 0 && error("gmshFltkRun returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -5338,11 +5338,11 @@ Return an integer value.
 """
 function isAvailable()
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshFltkIsAvailable, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshFltkIsAvailable, gmsh.lib), Cint,
           (Ptr{Cint},),
           ierr)
-    ierr[] != 0 && error("gmshFltkIsAvailable returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -5357,13 +5357,13 @@ function selectEntities(dim = -1)
     api_dimTags_ = Ref{Ptr{Cint}}()
     api_dimTags_n_ = Ref{Csize_t}()
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshFltkSelectEntities, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshFltkSelectEntities, gmsh.lib), Cint,
           (Ptr{Ptr{Cint}}, Ptr{Csize_t}, Cint, Ptr{Cint}),
           api_dimTags_, api_dimTags_n_, dim, ierr)
-    ierr[] != 0 && error("gmshFltkSelectEntities returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     tmp_api_dimTags_ = unsafe_wrap(Array, api_dimTags_[], api_dimTags_n_[], own=true)
     dimTags = [ (tmp_api_dimTags_[i], tmp_api_dimTags_[i+1]) for i in 1:2:length(tmp_api_dimTags_) ]
-    return api__result__, dimTags
+    return api_result_, dimTags
 end
 
 """
@@ -5377,12 +5377,12 @@ function selectElements()
     api_elementTags_ = Ref{Ptr{Csize_t}}()
     api_elementTags_n_ = Ref{Csize_t}()
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshFltkSelectElements, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshFltkSelectElements, gmsh.lib), Cint,
           (Ptr{Ptr{Csize_t}}, Ptr{Csize_t}, Ptr{Cint}),
           api_elementTags_, api_elementTags_n_, ierr)
-    ierr[] != 0 && error("gmshFltkSelectElements returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     elementTags = unsafe_wrap(Array, api_elementTags_[], api_elementTags_n_[], own=true)
-    return api__result__, elementTags
+    return api_result_, elementTags
 end
 
 """
@@ -5396,12 +5396,12 @@ function selectViews()
     api_viewTags_ = Ref{Ptr{Cint}}()
     api_viewTags_n_ = Ref{Csize_t}()
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshFltkSelectViews, gmsh.lib), Cint,
+    api_result_ = ccall((:gmshFltkSelectViews, gmsh.lib), Cint,
           (Ptr{Ptr{Cint}}, Ptr{Csize_t}, Ptr{Cint}),
           api_viewTags_, api_viewTags_n_, ierr)
-    ierr[] != 0 && error("gmshFltkSelectViews returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     viewTags = unsafe_wrap(Array, api_viewTags_[], api_viewTags_n_[], own=true)
-    return api__result__, viewTags
+    return api_result_, viewTags
 end
 
 end # end of module fltk
@@ -5425,7 +5425,7 @@ function set(data, format = "json")
     ccall((:gmshOnelabSet, gmsh.lib), Cvoid,
           (Ptr{Cchar}, Ptr{Cchar}, Ptr{Cint}),
           data, format, ierr)
-    ierr[] != 0 && error("gmshOnelabSet returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -5443,7 +5443,7 @@ function get(name = "", format = "json")
     ccall((:gmshOnelabGet, gmsh.lib), Cvoid,
           (Ptr{Ptr{Cchar}}, Ptr{Cchar}, Ptr{Cchar}, Ptr{Cint}),
           api_data_, name, format, ierr)
-    ierr[] != 0 && error("gmshOnelabGet returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     data = unsafe_string(api_data_[])
     return data
 end
@@ -5459,7 +5459,7 @@ function setNumber(name, value)
     ccall((:gmshOnelabSetNumber, gmsh.lib), Cvoid,
           (Ptr{Cchar}, Ptr{Cdouble}, Csize_t, Ptr{Cint}),
           name, convert(Vector{Cdouble}, value), length(value), ierr)
-    ierr[] != 0 && error("gmshOnelabSetNumber returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -5474,7 +5474,7 @@ function setString(name, value)
     ccall((:gmshOnelabSetString, gmsh.lib), Cvoid,
           (Ptr{Cchar}, Ptr{Ptr{Cchar}}, Csize_t, Ptr{Cint}),
           name, value, length(value), ierr)
-    ierr[] != 0 && error("gmshOnelabSetString returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -5493,7 +5493,7 @@ function getNumber(name)
     ccall((:gmshOnelabGetNumber, gmsh.lib), Cvoid,
           (Ptr{Cchar}, Ptr{Ptr{Cdouble}}, Ptr{Csize_t}, Ptr{Cint}),
           name, api_value_, api_value_n_, ierr)
-    ierr[] != 0 && error("gmshOnelabGetNumber returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     value = unsafe_wrap(Array, api_value_[], api_value_n_[], own=true)
     return value
 end
@@ -5513,7 +5513,7 @@ function getString(name)
     ccall((:gmshOnelabGetString, gmsh.lib), Cvoid,
           (Ptr{Cchar}, Ptr{Ptr{Ptr{Cchar}}}, Ptr{Csize_t}, Ptr{Cint}),
           name, api_value_, api_value_n_, ierr)
-    ierr[] != 0 && error("gmshOnelabGetString returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     tmp_api_value_ = unsafe_wrap(Array, api_value_[], api_value_n_[], own=true)
     value = [unsafe_string(tmp_api_value_[i]) for i in 1:length(tmp_api_value_) ]
     return value
@@ -5529,7 +5529,7 @@ function clear(name = "")
     ccall((:gmshOnelabClear, gmsh.lib), Cvoid,
           (Ptr{Cchar}, Ptr{Cint}),
           name, ierr)
-    ierr[] != 0 && error("gmshOnelabClear returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -5545,7 +5545,7 @@ function run(name = "", command = "")
     ccall((:gmshOnelabRun, gmsh.lib), Cvoid,
           (Ptr{Cchar}, Ptr{Cchar}, Ptr{Cint}),
           name, command, ierr)
-    ierr[] != 0 && error("gmshOnelabRun returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -5570,7 +5570,7 @@ function write(message, level = "info")
     ccall((:gmshLoggerWrite, gmsh.lib), Cvoid,
           (Ptr{Cchar}, Ptr{Cchar}, Ptr{Cint}),
           message, level, ierr)
-    ierr[] != 0 && error("gmshLoggerWrite returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -5584,7 +5584,7 @@ function start()
     ccall((:gmshLoggerStart, gmsh.lib), Cvoid,
           (Ptr{Cint},),
           ierr)
-    ierr[] != 0 && error("gmshLoggerStart returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -5602,7 +5602,7 @@ function get()
     ccall((:gmshLoggerGet, gmsh.lib), Cvoid,
           (Ptr{Ptr{Ptr{Cchar}}}, Ptr{Csize_t}, Ptr{Cint}),
           api_log_, api_log_n_, ierr)
-    ierr[] != 0 && error("gmshLoggerGet returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     tmp_api_log_ = unsafe_wrap(Array, api_log_[], api_log_n_[], own=true)
     log = [unsafe_string(tmp_api_log_[i]) for i in 1:length(tmp_api_log_) ]
     return log
@@ -5618,7 +5618,7 @@ function stop()
     ccall((:gmshLoggerStop, gmsh.lib), Cvoid,
           (Ptr{Cint},),
           ierr)
-    ierr[] != 0 && error("gmshLoggerStop returned non-zero error code: $(ierr[])")
+    ierr[] != 0 && error(gmsh.logger.getLastError())
     return nothing
 end
 
@@ -5631,11 +5631,11 @@ Return a floating point value.
 """
 function getWallTime()
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshLoggerGetWallTime, gmsh.lib), Cdouble,
+    api_result_ = ccall((:gmshLoggerGetWallTime, gmsh.lib), Cdouble,
           (Ptr{Cint},),
           ierr)
-    ierr[] != 0 && error("gmshLoggerGetWallTime returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
 end
 
 """
@@ -5647,11 +5647,29 @@ Return a floating point value.
 """
 function getCpuTime()
     ierr = Ref{Cint}()
-    api__result__ = ccall((:gmshLoggerGetCpuTime, gmsh.lib), Cdouble,
+    api_result_ = ccall((:gmshLoggerGetCpuTime, gmsh.lib), Cdouble,
           (Ptr{Cint},),
           ierr)
-    ierr[] != 0 && error("gmshLoggerGetCpuTime returned non-zero error code: $(ierr[])")
-    return api__result__
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    return api_result_
+end
+
+"""
+    gmsh.logger.getLastError()
+
+Return last error message, if any.
+
+Return `error`.
+"""
+function getLastError()
+    api_error_ = Ref{Ptr{Cchar}}()
+    ierr = Ref{Cint}()
+    ccall((:gmshLoggerGetLastError, gmsh.lib), Cvoid,
+          (Ptr{Ptr{Cchar}}, Ptr{Cint}),
+          api_error_, ierr)
+    ierr[] != 0 && error(gmsh.logger.getLastError())
+    error = unsafe_string(api_error_[])
+    return error
 end
 
 end # end of module logger
diff --git a/api/gmsh.py b/api/gmsh.py
index 03bc6cb87a..d8d1ca5a40 100644
--- a/api/gmsh.py
+++ b/api/gmsh.py
@@ -199,9 +199,7 @@ def initialize(argv=[], readConfigFiles=True):
         c_int(bool(readConfigFiles)),
         byref(ierr))
     if ierr.value != 0:
-        raise ValueError(
-            "gmshInitialize returned non-zero error code: ",
-            ierr.value)
+        raise Exception(logger.getLastError())
 
 def finalize():
     """
@@ -214,9 +212,7 @@ def finalize():
         byref(ierr))
     signal.signal(signal.SIGINT, oldsig)
     if ierr.value != 0:
-        raise ValueError(
-            "gmshFinalize returned non-zero error code: ",
-            ierr.value)
+        raise Exception(logger.getLastError())
 
 def open(fileName):
     """
@@ -231,9 +227,7 @@ def open(fileName):
         c_char_p(fileName.encode()),
         byref(ierr))
     if ierr.value != 0:
-        raise ValueError(
-            "gmshOpen returned non-zero error code: ",
-            ierr.value)
+        raise Exception(logger.getLastError())
 
 def merge(fileName):
     """
@@ -248,9 +242,7 @@ def merge(fileName):
         c_char_p(fileName.encode()),
         byref(ierr))
     if ierr.value != 0:
-        raise ValueError(
-            "gmshMerge returned non-zero error code: ",
-            ierr.value)
+        raise Exception(logger.getLastError())
 
 def write(fileName):
     """
@@ -263,9 +255,7 @@ def write(fileName):
         c_char_p(fileName.encode()),
         byref(ierr))
     if ierr.value != 0:
-        raise ValueError(
-            "gmshWrite returned non-zero error code: ",
-            ierr.value)
+        raise Exception(logger.getLastError())
 
 def clear():
     """
@@ -278,9 +268,7 @@ def clear():
     lib.gmshClear(
         byref(ierr))
     if ierr.value != 0:
-        raise ValueError(
-            "gmshClear returned non-zero error code: ",
-            ierr.value)
+        raise Exception(logger.getLastError())
 
 
 class option:
@@ -303,9 +291,7 @@ class option:
             c_double(value),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshOptionSetNumber returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
     @staticmethod
     def getNumber(name):
@@ -325,9 +311,7 @@ class option:
             byref(api_value_),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshOptionGetNumber returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return api_value_.value
 
     @staticmethod
@@ -345,9 +329,7 @@ class option:
             c_char_p(value.encode()),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshOptionSetString returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
     @staticmethod
     def getString(name):
@@ -367,9 +349,7 @@ class option:
             byref(api_value_),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshOptionGetString returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return _ostring(api_value_)
 
     @staticmethod
@@ -392,9 +372,7 @@ class option:
             c_int(a),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshOptionSetColor returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
     @staticmethod
     def getColor(name):
@@ -421,9 +399,7 @@ class option:
             byref(api_a_),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshOptionGetColor returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return (
             api_r_.value,
             api_g_.value,
@@ -448,9 +424,7 @@ class model:
             c_char_p(name.encode()),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelAdd returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
     @staticmethod
     def remove():
@@ -463,9 +437,7 @@ class model:
         lib.gmshModelRemove(
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelRemove returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
     @staticmethod
     def list():
@@ -482,9 +454,7 @@ class model:
             byref(api_names_), byref(api_names_n_),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelList returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return _ovectorstring(api_names_, api_names_n_.value)
 
     @staticmethod
@@ -502,9 +472,7 @@ class model:
             byref(api_name_),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelGetCurrent returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return _ostring(api_name_)
 
     @staticmethod
@@ -520,9 +488,7 @@ class model:
             c_char_p(name.encode()),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelSetCurrent returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
     @staticmethod
     def getEntities(dim=-1):
@@ -542,9 +508,7 @@ class model:
             c_int(dim),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelGetEntities returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return _ovectorpair(api_dimTags_, api_dimTags_n_.value)
 
     @staticmethod
@@ -561,9 +525,7 @@ class model:
             c_char_p(name.encode()),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelSetEntityName returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
     @staticmethod
     def getEntityName(dim, tag):
@@ -582,9 +544,7 @@ class model:
             byref(api_name_),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelGetEntityName returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return _ostring(api_name_)
 
     @staticmethod
@@ -605,9 +565,7 @@ class model:
             c_int(dim),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelGetPhysicalGroups returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return _ovectorpair(api_dimTags_, api_dimTags_n_.value)
 
     @staticmethod
@@ -628,9 +586,7 @@ class model:
             byref(api_tags_), byref(api_tags_n_),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelGetEntitiesForPhysicalGroup returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return _ovectorint(api_tags_, api_tags_n_.value)
 
     @staticmethod
@@ -651,9 +607,7 @@ class model:
             byref(api_physicalTags_), byref(api_physicalTags_n_),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelGetPhysicalGroupsForEntity returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return _ovectorint(api_physicalTags_, api_physicalTags_n_.value)
 
     @staticmethod
@@ -669,16 +623,14 @@ class model:
         """
         api_tags_, api_tags_n_ = _ivectorint(tags)
         ierr = c_int()
-        api__result__ = lib.gmshModelAddPhysicalGroup(
+        api_result_ = lib.gmshModelAddPhysicalGroup(
             c_int(dim),
             api_tags_, api_tags_n_,
             c_int(tag),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelAddPhysicalGroup returned non-zero error code: ",
-                ierr.value)
-        return api__result__
+            raise Exception(logger.getLastError())
+        return api_result_
 
     @staticmethod
     def setPhysicalName(dim, tag, name):
@@ -694,9 +646,7 @@ class model:
             c_char_p(name.encode()),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelSetPhysicalName returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
     @staticmethod
     def getPhysicalName(dim, tag):
@@ -715,9 +665,7 @@ class model:
             byref(api_name_),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelGetPhysicalName returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return _ostring(api_name_)
 
     @staticmethod
@@ -745,9 +693,7 @@ class model:
             c_int(bool(recursive)),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelGetBoundary returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return _ovectorpair(api_outDimTags_, api_outDimTags_n_.value)
 
     @staticmethod
@@ -775,9 +721,7 @@ class model:
             c_int(dim),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelGetEntitiesInBoundingBox returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return _ovectorpair(api_tags_, api_tags_n_.value)
 
     @staticmethod
@@ -809,9 +753,7 @@ class model:
             byref(api_zmax_),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelGetBoundingBox returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return (
             api_xmin_.value,
             api_ymin_.value,
@@ -830,13 +772,11 @@ class model:
         Return an integer value.
         """
         ierr = c_int()
-        api__result__ = lib.gmshModelGetDimension(
+        api_result_ = lib.gmshModelGetDimension(
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelGetDimension returned non-zero error code: ",
-                ierr.value)
-        return api__result__
+            raise Exception(logger.getLastError())
+        return api_result_
 
     @staticmethod
     def addDiscreteEntity(dim, tag=-1, boundary=[]):
@@ -853,16 +793,14 @@ class model:
         """
         api_boundary_, api_boundary_n_ = _ivectorint(boundary)
         ierr = c_int()
-        api__result__ = lib.gmshModelAddDiscreteEntity(
+        api_result_ = lib.gmshModelAddDiscreteEntity(
             c_int(dim),
             c_int(tag),
             api_boundary_, api_boundary_n_,
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelAddDiscreteEntity returned non-zero error code: ",
-                ierr.value)
-        return api__result__
+            raise Exception(logger.getLastError())
+        return api_result_
 
     @staticmethod
     def removeEntities(dimTags, recursive=False):
@@ -879,9 +817,7 @@ class model:
             c_int(bool(recursive)),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelRemoveEntities returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
     @staticmethod
     def removeEntityName(name):
@@ -895,9 +831,7 @@ class model:
             c_char_p(name.encode()),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelRemoveEntityName returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
     @staticmethod
     def removePhysicalGroups(dimTags=[]):
@@ -913,9 +847,7 @@ class model:
             api_dimTags_, api_dimTags_n_,
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelRemovePhysicalGroups returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
     @staticmethod
     def removePhysicalName(name):
@@ -929,9 +861,7 @@ class model:
             c_char_p(name.encode()),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelRemovePhysicalName returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
     @staticmethod
     def getType(dim, tag):
@@ -950,9 +880,7 @@ class model:
             byref(api_entityType_),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelGetType returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return _ostring(api_entityType_)
 
     @staticmethod
@@ -976,9 +904,7 @@ class model:
             byref(api_parentTag_),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelGetParent returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return (
             api_parentDim_.value,
             api_parentTag_.value)
@@ -1001,9 +927,7 @@ class model:
             byref(api_partitions_), byref(api_partitions_n_),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelGetPartitions returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return _ovectorint(api_partitions_, api_partitions_n_.value)
 
     @staticmethod
@@ -1031,9 +955,7 @@ class model:
             byref(api_coord_), byref(api_coord_n_),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelGetValue returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return _ovectordouble(api_coord_, api_coord_n_.value)
 
     @staticmethod
@@ -1063,9 +985,7 @@ class model:
             byref(api_derivatives_), byref(api_derivatives_n_),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelGetDerivative returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return _ovectordouble(api_derivatives_, api_derivatives_n_.value)
 
     @staticmethod
@@ -1091,9 +1011,7 @@ class model:
             byref(api_curvatures_), byref(api_curvatures_n_),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelGetCurvature returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return _ovectordouble(api_curvatures_, api_curvatures_n_.value)
 
     @staticmethod
@@ -1123,9 +1041,7 @@ class model:
             byref(api_directionMin_), byref(api_directionMin_n_),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelGetPrincipalCurvatures returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return (
             _ovectordouble(api_curvatureMax_, api_curvatureMax_n_.value),
             _ovectordouble(api_curvatureMin_, api_curvatureMin_n_.value),
@@ -1153,9 +1069,7 @@ class model:
             byref(api_normals_), byref(api_normals_n_),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelGetNormal returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return _ovectordouble(api_normals_, api_normals_n_.value)
 
     @staticmethod
@@ -1182,9 +1096,7 @@ class model:
             byref(api_parametricCoord_), byref(api_parametricCoord_n_),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelGetParametrization returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return _ovectordouble(api_parametricCoord_, api_parametricCoord_n_.value)
 
     @staticmethod
@@ -1207,9 +1119,7 @@ class model:
             byref(api_max_), byref(api_max_n_),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelGetParametrizationBounds returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return (
             _ovectordouble(api_min_, api_min_n_.value),
             _ovectordouble(api_max_, api_max_n_.value))
@@ -1229,16 +1139,14 @@ class model:
         """
         api_parametricCoord_, api_parametricCoord_n_ = _ivectordouble(parametricCoord)
         ierr = c_int()
-        api__result__ = lib.gmshModelIsInside(
+        api_result_ = lib.gmshModelIsInside(
             c_int(dim),
             c_int(tag),
             api_parametricCoord_, api_parametricCoord_n_,
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelIsInside returned non-zero error code: ",
-                ierr.value)
-        return api__result__
+            raise Exception(logger.getLastError())
+        return api_result_
 
     @staticmethod
     def getClosestPoint(dim, tag, coord):
@@ -1267,9 +1175,7 @@ class model:
             byref(api_parametricCoord_), byref(api_parametricCoord_n_),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelGetClosestPoint returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return (
             _ovectordouble(api_closestCoord_, api_closestCoord_n_.value),
             _ovectordouble(api_parametricCoord_, api_parametricCoord_n_.value))
@@ -1300,9 +1206,7 @@ class model:
             c_int(which),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelReparametrizeOnSurface returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return _ovectordouble(api_surfaceParametricCoord_, api_surfaceParametricCoord_n_.value)
 
     @staticmethod
@@ -1321,9 +1225,7 @@ class model:
             c_int(bool(recursive)),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelSetVisibility returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
     @staticmethod
     def getVisibility(dim, tag):
@@ -1342,9 +1244,7 @@ class model:
             byref(api_value_),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelGetVisibility returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return api_value_.value
 
     @staticmethod
@@ -1367,9 +1267,7 @@ class model:
             c_int(bool(recursive)),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelSetColor returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
     @staticmethod
     def getColor(dim, tag):
@@ -1394,9 +1292,7 @@ class model:
             byref(api_a_),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelGetColor returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return (
             api_r_.value,
             api_g_.value,
@@ -1418,9 +1314,7 @@ class model:
             c_double(z),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshModelSetCoordinates returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
 
     class mesh:
@@ -1440,9 +1334,7 @@ class model:
                 c_int(dim),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshGenerate returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def partition(numPart):
@@ -1456,9 +1348,7 @@ class model:
                 c_int(numPart),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshPartition returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def unpartition():
@@ -1471,9 +1361,7 @@ class model:
             lib.gmshModelMeshUnpartition(
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshUnpartition returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def optimize(method, force=False, niter=1, dimTags=[]):
@@ -1497,9 +1385,7 @@ class model:
                 api_dimTags_, api_dimTags_n_,
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshOptimize returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def recombine():
@@ -1512,9 +1398,7 @@ class model:
             lib.gmshModelMeshRecombine(
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshRecombine returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def refine():
@@ -1527,9 +1411,7 @@ class model:
             lib.gmshModelMeshRefine(
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshRefine returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def setOrder(order):
@@ -1543,9 +1425,7 @@ class model:
                 c_int(order),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshSetOrder returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def getLastEntityError():
@@ -1563,9 +1443,7 @@ class model:
                 byref(api_dimTags_), byref(api_dimTags_n_),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshGetLastEntityError returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return _ovectorpair(api_dimTags_, api_dimTags_n_.value)
 
         @staticmethod
@@ -1584,9 +1462,7 @@ class model:
                 byref(api_nodeTags_), byref(api_nodeTags_n_),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshGetLastNodeError returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return _ovectorsize(api_nodeTags_, api_nodeTags_n_.value)
 
         @staticmethod
@@ -1605,9 +1481,7 @@ class model:
                 api_dimTags_, api_dimTags_n_,
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshClear returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def getNodes(dim=-1, tag=-1, includeBoundary=False, returnParametricCoord=True):
@@ -1644,9 +1518,7 @@ class model:
                 c_int(bool(returnParametricCoord)),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshGetNodes returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return (
                 _ovectorsize(api_nodeTags_, api_nodeTags_n_.value),
                 _ovectordouble(api_coord_, api_coord_n_.value),
@@ -1675,9 +1547,7 @@ class model:
                 c_int(bool(returnParametricCoord)),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshGetNodesByElementType returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return (
                 _ovectorsize(api_nodeTags_, api_nodeTags_n_.value),
                 _ovectordouble(api_coord_, api_coord_n_.value),
@@ -1704,9 +1574,7 @@ class model:
                 byref(api_parametricCoord_), byref(api_parametricCoord_n_),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshGetNode returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return (
                 _ovectordouble(api_coord_, api_coord_n_.value),
                 _ovectordouble(api_parametricCoord_, api_parametricCoord_n_.value))
@@ -1730,9 +1598,7 @@ class model:
                 api_parametricCoord_, api_parametricCoord_n_,
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshSetNode returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def rebuildNodeCache(onlyIfNecessary=True):
@@ -1746,9 +1612,7 @@ class model:
                 c_int(bool(onlyIfNecessary)),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshRebuildNodeCache returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def rebuildElementCache(onlyIfNecessary=True):
@@ -1762,9 +1626,7 @@ class model:
                 c_int(bool(onlyIfNecessary)),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshRebuildElementCache returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def getNodesForPhysicalGroup(dim, tag):
@@ -1788,9 +1650,7 @@ class model:
                 byref(api_coord_), byref(api_coord_n_),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshGetNodesForPhysicalGroup returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return (
                 _ovectorsize(api_nodeTags_, api_nodeTags_n_.value),
                 _ovectordouble(api_coord_, api_coord_n_.value))
@@ -1822,9 +1682,7 @@ class model:
                 api_parametricCoord_, api_parametricCoord_n_,
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshAddNodes returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def reclassifyNodes():
@@ -1840,9 +1698,7 @@ class model:
             lib.gmshModelMeshReclassifyNodes(
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshReclassifyNodes returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def relocateNodes(dim=-1, tag=-1):
@@ -1860,9 +1716,7 @@ class model:
                 c_int(tag),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshRelocateNodes returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def getElements(dim=-1, tag=-1):
@@ -1897,9 +1751,7 @@ class model:
                 c_int(tag),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshGetElements returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return (
                 _ovectorint(api_elementTypes_, api_elementTypes_n_.value),
                 _ovectorvectorsize(api_elementTags_, api_elementTags_n_, api_elementTags_nn_),
@@ -1926,9 +1778,7 @@ class model:
                 byref(api_nodeTags_), byref(api_nodeTags_n_),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshGetElement returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return (
                 api_elementType_.value,
                 _ovectorsize(api_nodeTags_, api_nodeTags_n_.value))
@@ -1968,9 +1818,7 @@ class model:
                 c_int(bool(strict)),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshGetElementByCoordinates returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return (
                 api_elementTag_.value,
                 api_elementType_.value,
@@ -2004,9 +1852,7 @@ class model:
                 c_int(bool(strict)),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshGetElementsByCoordinates returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return _ovectorsize(api_elementTags_, api_elementTags_n_.value)
 
         @staticmethod
@@ -2036,9 +1882,7 @@ class model:
                 byref(api_w_),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshGetLocalCoordinatesInElement returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return (
                 api_u_.value,
                 api_v_.value,
@@ -2063,9 +1907,7 @@ class model:
                 c_int(tag),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshGetElementTypes returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return _ovectorint(api_elementTypes_, api_elementTypes_n_.value)
 
         @staticmethod
@@ -2081,16 +1923,14 @@ class model:
             Return an integer value.
             """
             ierr = c_int()
-            api__result__ = lib.gmshModelMeshGetElementType(
+            api_result_ = lib.gmshModelMeshGetElementType(
                 c_char_p(familyName.encode()),
                 c_int(order),
                 c_int(bool(serendip)),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshGetElementType returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def getElementProperties(elementType):
@@ -2122,9 +1962,7 @@ class model:
                 byref(api_numPrimaryNodes_),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshGetElementProperties returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return (
                 _ostring(api_elementName_),
                 api_dim_.value,
@@ -2162,9 +2000,7 @@ class model:
                 c_size_t(numTasks),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshGetElementsByType returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return (
                 _ovectorsize(api_elementTags_, api_elementTags_n_.value),
                 _ovectorsize(api_nodeTags_, api_nodeTags_n_.value))
@@ -2197,9 +2033,7 @@ class model:
                 api_nodeTags_, api_nodeTags_n_, api_nodeTags_nn_,
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshAddElements returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def addElementsByType(tag, elementType, elementTags, nodeTags):
@@ -2224,9 +2058,7 @@ class model:
                 api_nodeTags_, api_nodeTags_n_,
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshAddElementsByType returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def getIntegrationPoints(elementType, integrationType):
@@ -2252,9 +2084,7 @@ class model:
                 byref(api_weights_), byref(api_weights_n_),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshGetIntegrationPoints returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return (
                 _ovectordouble(api_localCoord_, api_localCoord_n_.value),
                 _ovectordouble(api_weights_, api_weights_n_.value))
@@ -2297,9 +2127,7 @@ class model:
                 c_size_t(numTasks),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshGetJacobians returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return (
                 _ovectordouble(api_jacobians_, api_jacobians_n_.value),
                 _ovectordouble(api_determinants_, api_determinants_n_.value),
@@ -2337,9 +2165,7 @@ class model:
                 byref(api_coord_), byref(api_coord_n_),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshGetJacobian returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return (
                 _ovectordouble(api_jacobians_, api_jacobians_n_.value),
                 _ovectordouble(api_determinants_, api_determinants_n_.value),
@@ -2385,9 +2211,7 @@ class model:
                 api_wantedOrientations_, api_wantedOrientations_n_,
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshGetBasisFunctions returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return (
                 api_numComponents_.value,
                 _ovectordouble(api_basisFunctions_, api_basisFunctions_n_.value),
@@ -2418,9 +2242,7 @@ class model:
                 c_size_t(numTasks),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshGetBasisFunctionsOrientationForElements returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return _ovectorint(api_basisFunctionsOrientation_, api_basisFunctionsOrientation_n_.value)
 
         @staticmethod
@@ -2440,9 +2262,7 @@ class model:
                 byref(api_basisFunctionsOrientation_),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshGetBasisFunctionsOrientationForElement returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return api_basisFunctionsOrientation_.value
 
         @staticmethod
@@ -2456,15 +2276,13 @@ class model:
             Return an integer value.
             """
             ierr = c_int()
-            api__result__ = lib.gmshModelMeshGetNumberOfOrientations(
+            api_result_ = lib.gmshModelMeshGetNumberOfOrientations(
                 c_int(elementType),
                 c_char_p(functionSpaceType.encode()),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshGetNumberOfOrientations returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def getEdgeNumber(edgeNodes):
@@ -2485,9 +2303,7 @@ class model:
                 byref(api_edgeNum_), byref(api_edgeNum_n_),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshGetEdgeNumber returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return _ovectorint(api_edgeNum_, api_edgeNum_n_.value)
 
         @staticmethod
@@ -2509,9 +2325,7 @@ class model:
                 c_int(tag),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshGetLocalMultipliersForHcurl0 returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return _ovectorint(api_localMultipliers_, api_localMultipliers_n_.value)
 
         @staticmethod
@@ -2540,9 +2354,7 @@ class model:
                 c_int(bool(returnCoord)),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshGetKeysForElements returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return (
                 _ovectorpair(api_keys_, api_keys_n_.value),
                 _ovectordouble(api_coord_, api_coord_n_.value))
@@ -2567,9 +2379,7 @@ class model:
                 c_int(bool(returnCoord)),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshGetKeysForElement returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return (
                 _ovectorpair(api_keys_, api_keys_n_.value),
                 _ovectordouble(api_coord_, api_coord_n_.value))
@@ -2585,15 +2395,13 @@ class model:
             Return an integer value.
             """
             ierr = c_int()
-            api__result__ = lib.gmshModelMeshGetNumberOfKeysForElements(
+            api_result_ = lib.gmshModelMeshGetNumberOfKeysForElements(
                 c_int(elementType),
                 c_char_p(functionSpaceType.encode()),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshGetNumberOfKeysForElements returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def getInformationForElements(keys, elementType, functionSpaceType):
@@ -2619,9 +2427,7 @@ class model:
                 byref(api_infoKeys_), byref(api_infoKeys_n_),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshGetInformationForElements returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return _ovectorpair(api_infoKeys_, api_infoKeys_n_.value)
 
         @staticmethod
@@ -2651,9 +2457,7 @@ class model:
                 c_size_t(numTasks),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshGetBarycenters returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return _ovectordouble(api_barycenters_, api_barycenters_n_.value)
 
         @staticmethod
@@ -2683,9 +2487,7 @@ class model:
                 c_size_t(numTasks),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshGetElementEdgeNodes returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return _ovectorsize(api_nodeTags_, api_nodeTags_n_.value)
 
         @staticmethod
@@ -2717,9 +2519,7 @@ class model:
                 c_size_t(numTasks),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshGetElementFaceNodes returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return _ovectorsize(api_nodeTags_, api_nodeTags_n_.value)
 
         @staticmethod
@@ -2742,9 +2542,7 @@ class model:
                 byref(api_partitions_), byref(api_partitions_n_),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshGetGhostElements returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return (
                 _ovectorsize(api_elementTags_, api_elementTags_n_.value),
                 _ovectorint(api_partitions_, api_partitions_n_.value))
@@ -2764,9 +2562,7 @@ class model:
                 c_double(size),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshSetSize returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def setSizeAtParametricPoints(dim, tag, parametricCoord, sizes):
@@ -2787,9 +2583,7 @@ class model:
                 api_sizes_, api_sizes_n_,
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshSetSizeAtParametricPoints returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def setTransfiniteCurve(tag, numNodes, meshType="Progression", coef=1.):
@@ -2809,9 +2603,7 @@ class model:
                 c_double(coef),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshSetTransfiniteCurve returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def setTransfiniteSurface(tag, arrangement="Left", cornerTags=[]):
@@ -2834,9 +2626,7 @@ class model:
                 api_cornerTags_, api_cornerTags_n_,
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshSetTransfiniteSurface returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def setTransfiniteVolume(tag, cornerTags=[]):
@@ -2854,9 +2644,7 @@ class model:
                 api_cornerTags_, api_cornerTags_n_,
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshSetTransfiniteVolume returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def setRecombine(dim, tag):
@@ -2873,9 +2661,7 @@ class model:
                 c_int(tag),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshSetRecombine returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def setSmoothing(dim, tag, val):
@@ -2892,9 +2678,7 @@ class model:
                 c_int(val),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshSetSmoothing returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def setReverse(dim, tag, val=True):
@@ -2914,9 +2698,7 @@ class model:
                 c_int(bool(val)),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshSetReverse returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def setAlgorithm(dim, tag, val):
@@ -2933,9 +2715,7 @@ class model:
                 c_int(val),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshSetAlgorithm returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def setSizeFromBoundary(dim, tag, val):
@@ -2953,9 +2733,7 @@ class model:
                 c_int(val),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshSetSizeFromBoundary returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def setCompound(dim, tags):
@@ -2973,9 +2751,7 @@ class model:
                 api_tags_, api_tags_n_,
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshSetCompound returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def setOutwardOrientation(tag):
@@ -2992,9 +2768,7 @@ class model:
                 c_int(tag),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshSetOutwardOrientation returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def embed(dim, tags, inDim, inTag):
@@ -3016,9 +2790,7 @@ class model:
                 c_int(inTag),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshEmbed returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def removeEmbedded(dimTags, dim=-1):
@@ -3036,9 +2808,7 @@ class model:
                 c_int(dim),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshRemoveEmbedded returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def reorderElements(elementType, tag, ordering):
@@ -3056,9 +2826,7 @@ class model:
                 api_ordering_, api_ordering_n_,
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshReorderElements returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def renumberNodes():
@@ -3071,9 +2839,7 @@ class model:
             lib.gmshModelMeshRenumberNodes(
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshRenumberNodes returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def renumberElements():
@@ -3086,9 +2852,7 @@ class model:
             lib.gmshModelMeshRenumberElements(
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshRenumberElements returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def setPeriodic(dim, tags, tagsMaster, affineTransform):
@@ -3115,9 +2879,7 @@ class model:
                 api_affineTransform_, api_affineTransform_n_,
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshSetPeriodic returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def getPeriodicNodes(dim, tag, includeHighOrderNodes=False):
@@ -3147,9 +2909,7 @@ class model:
                 c_int(bool(includeHighOrderNodes)),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshGetPeriodicNodes returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return (
                 api_tagMaster_.value,
                 _ovectorsize(api_nodeTags_, api_nodeTags_n_.value),
@@ -3167,9 +2927,7 @@ class model:
             lib.gmshModelMeshRemoveDuplicateNodes(
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshRemoveDuplicateNodes returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def splitQuadrangles(quality=1., tag=-1):
@@ -3185,9 +2943,7 @@ class model:
                 c_int(tag),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshSplitQuadrangles returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def classifySurfaces(angle, boundary=True, forReparametrization=False, curveAngle=pi):
@@ -3210,9 +2966,7 @@ class model:
                 c_double(curveAngle),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshClassifySurfaces returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def createGeometry(dimTags=[]):
@@ -3231,9 +2985,7 @@ class model:
                 api_dimTags_, api_dimTags_n_,
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshCreateGeometry returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def createTopology(makeSimplyConnected=True, exportDiscrete=True):
@@ -3253,9 +3005,7 @@ class model:
                 c_int(bool(exportDiscrete)),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshCreateTopology returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def computeHomology(domainTags=[], subdomainTags=[], dims=[]):
@@ -3281,9 +3031,7 @@ class model:
                 api_dims_, api_dims_n_,
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshComputeHomology returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def computeCohomology(domainTags=[], subdomainTags=[], dims=[]):
@@ -3309,9 +3057,7 @@ class model:
                 api_dims_, api_dims_n_,
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshComputeCohomology returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def computeCrossField():
@@ -3330,9 +3076,7 @@ class model:
                 byref(api_viewTags_), byref(api_viewTags_n_),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelMeshComputeCrossField returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return _ovectorint(api_viewTags_, api_viewTags_n_.value)
 
 
@@ -3353,15 +3097,13 @@ class model:
                 Return an integer value.
                 """
                 ierr = c_int()
-                api__result__ = lib.gmshModelMeshFieldAdd(
+                api_result_ = lib.gmshModelMeshFieldAdd(
                     c_char_p(fieldType.encode()),
                     c_int(tag),
                     byref(ierr))
                 if ierr.value != 0:
-                    raise ValueError(
-                        "gmshModelMeshFieldAdd returned non-zero error code: ",
-                        ierr.value)
-                return api__result__
+                    raise Exception(logger.getLastError())
+                return api_result_
 
             @staticmethod
             def remove(tag):
@@ -3375,9 +3117,7 @@ class model:
                     c_int(tag),
                     byref(ierr))
                 if ierr.value != 0:
-                    raise ValueError(
-                        "gmshModelMeshFieldRemove returned non-zero error code: ",
-                        ierr.value)
+                    raise Exception(logger.getLastError())
 
             @staticmethod
             def setNumber(tag, option, value):
@@ -3393,9 +3133,7 @@ class model:
                     c_double(value),
                     byref(ierr))
                 if ierr.value != 0:
-                    raise ValueError(
-                        "gmshModelMeshFieldSetNumber returned non-zero error code: ",
-                        ierr.value)
+                    raise Exception(logger.getLastError())
 
             @staticmethod
             def setString(tag, option, value):
@@ -3411,9 +3149,7 @@ class model:
                     c_char_p(value.encode()),
                     byref(ierr))
                 if ierr.value != 0:
-                    raise ValueError(
-                        "gmshModelMeshFieldSetString returned non-zero error code: ",
-                        ierr.value)
+                    raise Exception(logger.getLastError())
 
             @staticmethod
             def setNumbers(tag, option, value):
@@ -3430,9 +3166,7 @@ class model:
                     api_value_, api_value_n_,
                     byref(ierr))
                 if ierr.value != 0:
-                    raise ValueError(
-                        "gmshModelMeshFieldSetNumbers returned non-zero error code: ",
-                        ierr.value)
+                    raise Exception(logger.getLastError())
 
             @staticmethod
             def setAsBackgroundMesh(tag):
@@ -3446,9 +3180,7 @@ class model:
                     c_int(tag),
                     byref(ierr))
                 if ierr.value != 0:
-                    raise ValueError(
-                        "gmshModelMeshFieldSetAsBackgroundMesh returned non-zero error code: ",
-                        ierr.value)
+                    raise Exception(logger.getLastError())
 
             @staticmethod
             def setAsBoundaryLayer(tag):
@@ -3462,9 +3194,7 @@ class model:
                     c_int(tag),
                     byref(ierr))
                 if ierr.value != 0:
-                    raise ValueError(
-                        "gmshModelMeshFieldSetAsBoundaryLayer returned non-zero error code: ",
-                        ierr.value)
+                    raise Exception(logger.getLastError())
 
 
     class geo:
@@ -3487,7 +3217,7 @@ class model:
             Return an integer value.
             """
             ierr = c_int()
-            api__result__ = lib.gmshModelGeoAddPoint(
+            api_result_ = lib.gmshModelGeoAddPoint(
                 c_double(x),
                 c_double(y),
                 c_double(z),
@@ -3495,10 +3225,8 @@ class model:
                 c_int(tag),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelGeoAddPoint returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addLine(startTag, endTag, tag=-1):
@@ -3512,16 +3240,14 @@ class model:
             Return an integer value.
             """
             ierr = c_int()
-            api__result__ = lib.gmshModelGeoAddLine(
+            api_result_ = lib.gmshModelGeoAddLine(
                 c_int(startTag),
                 c_int(endTag),
                 c_int(tag),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelGeoAddLine returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addCircleArc(startTag, centerTag, endTag, tag=-1, nx=0., ny=0., nz=0.):
@@ -3537,7 +3263,7 @@ class model:
             Return an integer value.
             """
             ierr = c_int()
-            api__result__ = lib.gmshModelGeoAddCircleArc(
+            api_result_ = lib.gmshModelGeoAddCircleArc(
                 c_int(startTag),
                 c_int(centerTag),
                 c_int(endTag),
@@ -3547,10 +3273,8 @@ class model:
                 c_double(nz),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelGeoAddCircleArc returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addEllipseArc(startTag, centerTag, majorTag, endTag, tag=-1, nx=0., ny=0., nz=0.):
@@ -3567,7 +3291,7 @@ class model:
             Return an integer value.
             """
             ierr = c_int()
-            api__result__ = lib.gmshModelGeoAddEllipseArc(
+            api_result_ = lib.gmshModelGeoAddEllipseArc(
                 c_int(startTag),
                 c_int(centerTag),
                 c_int(majorTag),
@@ -3578,10 +3302,8 @@ class model:
                 c_double(nz),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelGeoAddEllipseArc returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addSpline(pointTags, tag=-1):
@@ -3597,15 +3319,13 @@ class model:
             """
             api_pointTags_, api_pointTags_n_ = _ivectorint(pointTags)
             ierr = c_int()
-            api__result__ = lib.gmshModelGeoAddSpline(
+            api_result_ = lib.gmshModelGeoAddSpline(
                 api_pointTags_, api_pointTags_n_,
                 c_int(tag),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelGeoAddSpline returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addBSpline(pointTags, tag=-1):
@@ -3621,15 +3341,13 @@ class model:
             """
             api_pointTags_, api_pointTags_n_ = _ivectorint(pointTags)
             ierr = c_int()
-            api__result__ = lib.gmshModelGeoAddBSpline(
+            api_result_ = lib.gmshModelGeoAddBSpline(
                 api_pointTags_, api_pointTags_n_,
                 c_int(tag),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelGeoAddBSpline returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addBezier(pointTags, tag=-1):
@@ -3644,15 +3362,13 @@ class model:
             """
             api_pointTags_, api_pointTags_n_ = _ivectorint(pointTags)
             ierr = c_int()
-            api__result__ = lib.gmshModelGeoAddBezier(
+            api_result_ = lib.gmshModelGeoAddBezier(
                 api_pointTags_, api_pointTags_n_,
                 c_int(tag),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelGeoAddBezier returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addPolyline(pointTags, tag=-1):
@@ -3668,15 +3384,13 @@ class model:
             """
             api_pointTags_, api_pointTags_n_ = _ivectorint(pointTags)
             ierr = c_int()
-            api__result__ = lib.gmshModelGeoAddPolyline(
+            api_result_ = lib.gmshModelGeoAddPolyline(
                 api_pointTags_, api_pointTags_n_,
                 c_int(tag),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelGeoAddPolyline returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addCompoundSpline(curveTags, numIntervals=5, tag=-1):
@@ -3692,16 +3406,14 @@ class model:
             """
             api_curveTags_, api_curveTags_n_ = _ivectorint(curveTags)
             ierr = c_int()
-            api__result__ = lib.gmshModelGeoAddCompoundSpline(
+            api_result_ = lib.gmshModelGeoAddCompoundSpline(
                 api_curveTags_, api_curveTags_n_,
                 c_int(numIntervals),
                 c_int(tag),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelGeoAddCompoundSpline returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addCompoundBSpline(curveTags, numIntervals=20, tag=-1):
@@ -3717,16 +3429,14 @@ class model:
             """
             api_curveTags_, api_curveTags_n_ = _ivectorint(curveTags)
             ierr = c_int()
-            api__result__ = lib.gmshModelGeoAddCompoundBSpline(
+            api_result_ = lib.gmshModelGeoAddCompoundBSpline(
                 api_curveTags_, api_curveTags_n_,
                 c_int(numIntervals),
                 c_int(tag),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelGeoAddCompoundBSpline returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addCurveLoop(curveTags, tag=-1):
@@ -3744,15 +3454,13 @@ class model:
             """
             api_curveTags_, api_curveTags_n_ = _ivectorint(curveTags)
             ierr = c_int()
-            api__result__ = lib.gmshModelGeoAddCurveLoop(
+            api_result_ = lib.gmshModelGeoAddCurveLoop(
                 api_curveTags_, api_curveTags_n_,
                 c_int(tag),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelGeoAddCurveLoop returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addPlaneSurface(wireTags, tag=-1):
@@ -3768,15 +3476,13 @@ class model:
             """
             api_wireTags_, api_wireTags_n_ = _ivectorint(wireTags)
             ierr = c_int()
-            api__result__ = lib.gmshModelGeoAddPlaneSurface(
+            api_result_ = lib.gmshModelGeoAddPlaneSurface(
                 api_wireTags_, api_wireTags_n_,
                 c_int(tag),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelGeoAddPlaneSurface returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addSurfaceFilling(wireTags, tag=-1, sphereCenterTag=-1):
@@ -3792,16 +3498,14 @@ class model:
             """
             api_wireTags_, api_wireTags_n_ = _ivectorint(wireTags)
             ierr = c_int()
-            api__result__ = lib.gmshModelGeoAddSurfaceFilling(
+            api_result_ = lib.gmshModelGeoAddSurfaceFilling(
                 api_wireTags_, api_wireTags_n_,
                 c_int(tag),
                 c_int(sphereCenterTag),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelGeoAddSurfaceFilling returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addSurfaceLoop(surfaceTags, tag=-1):
@@ -3816,15 +3520,13 @@ class model:
             """
             api_surfaceTags_, api_surfaceTags_n_ = _ivectorint(surfaceTags)
             ierr = c_int()
-            api__result__ = lib.gmshModelGeoAddSurfaceLoop(
+            api_result_ = lib.gmshModelGeoAddSurfaceLoop(
                 api_surfaceTags_, api_surfaceTags_n_,
                 c_int(tag),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelGeoAddSurfaceLoop returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addVolume(shellTags, tag=-1):
@@ -3840,15 +3542,13 @@ class model:
             """
             api_shellTags_, api_shellTags_n_ = _ivectorint(shellTags)
             ierr = c_int()
-            api__result__ = lib.gmshModelGeoAddVolume(
+            api_result_ = lib.gmshModelGeoAddVolume(
                 api_shellTags_, api_shellTags_n_,
                 c_int(tag),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelGeoAddVolume returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def extrude(dimTags, dx, dy, dz, numElements=[], heights=[], recombine=False):
@@ -3880,9 +3580,7 @@ class model:
                 c_int(bool(recombine)),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelGeoExtrude returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return _ovectorpair(api_outDimTags_, api_outDimTags_n_.value)
 
         @staticmethod
@@ -3920,9 +3618,7 @@ class model:
                 c_int(bool(recombine)),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelGeoRevolve returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return _ovectorpair(api_outDimTags_, api_outDimTags_n_.value)
 
         @staticmethod
@@ -3964,9 +3660,7 @@ class model:
                 c_int(bool(recombine)),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelGeoTwist returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return _ovectorpair(api_outDimTags_, api_outDimTags_n_.value)
 
         @staticmethod
@@ -3985,9 +3679,7 @@ class model:
                 c_double(dz),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelGeoTranslate returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def rotate(dimTags, x, y, z, ax, ay, az, angle):
@@ -4011,9 +3703,7 @@ class model:
                 c_double(angle),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelGeoRotate returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def dilate(dimTags, x, y, z, a, b, c):
@@ -4036,9 +3726,7 @@ class model:
                 c_double(c),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelGeoDilate returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def mirror(dimTags, a, b, c, d):
@@ -4058,9 +3746,7 @@ class model:
                 c_double(d),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelGeoMirror returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def symmetrize(dimTags, a, b, c, d):
@@ -4081,9 +3767,7 @@ class model:
                 c_double(d),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelGeoSymmetrize returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def copy(dimTags):
@@ -4102,9 +3786,7 @@ class model:
                 byref(api_outDimTags_), byref(api_outDimTags_n_),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelGeoCopy returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return _ovectorpair(api_outDimTags_, api_outDimTags_n_.value)
 
         @staticmethod
@@ -4122,9 +3804,7 @@ class model:
                 c_int(bool(recursive)),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelGeoRemove returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def removeAllDuplicates():
@@ -4138,9 +3818,7 @@ class model:
             lib.gmshModelGeoRemoveAllDuplicates(
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelGeoRemoveAllDuplicates returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def splitCurve(tag, pointTags):
@@ -4161,9 +3839,7 @@ class model:
                 byref(api_curveTags_), byref(api_curveTags_n_),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelGeoSplitCurve returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return _ovectorint(api_curveTags_, api_curveTags_n_.value)
 
         @staticmethod
@@ -4177,14 +3853,12 @@ class model:
             Return an integer value.
             """
             ierr = c_int()
-            api__result__ = lib.gmshModelGeoGetMaxTag(
+            api_result_ = lib.gmshModelGeoGetMaxTag(
                 c_int(dim),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelGeoGetMaxTag returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def setMaxTag(dim, maxTag):
@@ -4200,9 +3874,7 @@ class model:
                 c_int(maxTag),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelGeoSetMaxTag returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def synchronize():
@@ -4218,9 +3890,7 @@ class model:
             lib.gmshModelGeoSynchronize(
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelGeoSynchronize returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
 
         class mesh:
@@ -4243,9 +3913,7 @@ class model:
                     c_double(size),
                     byref(ierr))
                 if ierr.value != 0:
-                    raise ValueError(
-                        "gmshModelGeoMeshSetSize returned non-zero error code: ",
-                        ierr.value)
+                    raise Exception(logger.getLastError())
 
             @staticmethod
             def setTransfiniteCurve(tag, nPoints, meshType="Progression", coef=1.):
@@ -4265,9 +3933,7 @@ class model:
                     c_double(coef),
                     byref(ierr))
                 if ierr.value != 0:
-                    raise ValueError(
-                        "gmshModelGeoMeshSetTransfiniteCurve returned non-zero error code: ",
-                        ierr.value)
+                    raise Exception(logger.getLastError())
 
             @staticmethod
             def setTransfiniteSurface(tag, arrangement="Left", cornerTags=[]):
@@ -4290,9 +3956,7 @@ class model:
                     api_cornerTags_, api_cornerTags_n_,
                     byref(ierr))
                 if ierr.value != 0:
-                    raise ValueError(
-                        "gmshModelGeoMeshSetTransfiniteSurface returned non-zero error code: ",
-                        ierr.value)
+                    raise Exception(logger.getLastError())
 
             @staticmethod
             def setTransfiniteVolume(tag, cornerTags=[]):
@@ -4310,9 +3974,7 @@ class model:
                     api_cornerTags_, api_cornerTags_n_,
                     byref(ierr))
                 if ierr.value != 0:
-                    raise ValueError(
-                        "gmshModelGeoMeshSetTransfiniteVolume returned non-zero error code: ",
-                        ierr.value)
+                    raise Exception(logger.getLastError())
 
             @staticmethod
             def setRecombine(dim, tag, angle=45.):
@@ -4330,9 +3992,7 @@ class model:
                     c_double(angle),
                     byref(ierr))
                 if ierr.value != 0:
-                    raise ValueError(
-                        "gmshModelGeoMeshSetRecombine returned non-zero error code: ",
-                        ierr.value)
+                    raise Exception(logger.getLastError())
 
             @staticmethod
             def setSmoothing(dim, tag, val):
@@ -4349,9 +4009,7 @@ class model:
                     c_int(val),
                     byref(ierr))
                 if ierr.value != 0:
-                    raise ValueError(
-                        "gmshModelGeoMeshSetSmoothing returned non-zero error code: ",
-                        ierr.value)
+                    raise Exception(logger.getLastError())
 
             @staticmethod
             def setReverse(dim, tag, val=True):
@@ -4371,9 +4029,7 @@ class model:
                     c_int(bool(val)),
                     byref(ierr))
                 if ierr.value != 0:
-                    raise ValueError(
-                        "gmshModelGeoMeshSetReverse returned non-zero error code: ",
-                        ierr.value)
+                    raise Exception(logger.getLastError())
 
             @staticmethod
             def setAlgorithm(dim, tag, val):
@@ -4390,9 +4046,7 @@ class model:
                     c_int(val),
                     byref(ierr))
                 if ierr.value != 0:
-                    raise ValueError(
-                        "gmshModelGeoMeshSetAlgorithm returned non-zero error code: ",
-                        ierr.value)
+                    raise Exception(logger.getLastError())
 
             @staticmethod
             def setSizeFromBoundary(dim, tag, val):
@@ -4410,9 +4064,7 @@ class model:
                     c_int(val),
                     byref(ierr))
                 if ierr.value != 0:
-                    raise ValueError(
-                        "gmshModelGeoMeshSetSizeFromBoundary returned non-zero error code: ",
-                        ierr.value)
+                    raise Exception(logger.getLastError())
 
 
     class occ:
@@ -4435,7 +4087,7 @@ class model:
             Return an integer value.
             """
             ierr = c_int()
-            api__result__ = lib.gmshModelOccAddPoint(
+            api_result_ = lib.gmshModelOccAddPoint(
                 c_double(x),
                 c_double(y),
                 c_double(z),
@@ -4443,10 +4095,8 @@ class model:
                 c_int(tag),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccAddPoint returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addLine(startTag, endTag, tag=-1):
@@ -4460,16 +4110,14 @@ class model:
             Return an integer value.
             """
             ierr = c_int()
-            api__result__ = lib.gmshModelOccAddLine(
+            api_result_ = lib.gmshModelOccAddLine(
                 c_int(startTag),
                 c_int(endTag),
                 c_int(tag),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccAddLine returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addCircleArc(startTag, centerTag, endTag, tag=-1):
@@ -4484,17 +4132,15 @@ class model:
             Return an integer value.
             """
             ierr = c_int()
-            api__result__ = lib.gmshModelOccAddCircleArc(
+            api_result_ = lib.gmshModelOccAddCircleArc(
                 c_int(startTag),
                 c_int(centerTag),
                 c_int(endTag),
                 c_int(tag),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccAddCircleArc returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addCircle(x, y, z, r, tag=-1, angle1=0., angle2=2*pi):
@@ -4509,7 +4155,7 @@ class model:
             Return an integer value.
             """
             ierr = c_int()
-            api__result__ = lib.gmshModelOccAddCircle(
+            api_result_ = lib.gmshModelOccAddCircle(
                 c_double(x),
                 c_double(y),
                 c_double(z),
@@ -4519,10 +4165,8 @@ class model:
                 c_double(angle2),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccAddCircle returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addEllipseArc(startTag, centerTag, majorTag, endTag, tag=-1):
@@ -4538,7 +4182,7 @@ class model:
             Return an integer value.
             """
             ierr = c_int()
-            api__result__ = lib.gmshModelOccAddEllipseArc(
+            api_result_ = lib.gmshModelOccAddEllipseArc(
                 c_int(startTag),
                 c_int(centerTag),
                 c_int(majorTag),
@@ -4546,10 +4190,8 @@ class model:
                 c_int(tag),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccAddEllipseArc returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addEllipse(x, y, z, r1, r2, tag=-1, angle1=0., angle2=2*pi):
@@ -4568,7 +4210,7 @@ class model:
             Return an integer value.
             """
             ierr = c_int()
-            api__result__ = lib.gmshModelOccAddEllipse(
+            api_result_ = lib.gmshModelOccAddEllipse(
                 c_double(x),
                 c_double(y),
                 c_double(z),
@@ -4579,10 +4221,8 @@ class model:
                 c_double(angle2),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccAddEllipse returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addSpline(pointTags, tag=-1):
@@ -4598,15 +4238,13 @@ class model:
             """
             api_pointTags_, api_pointTags_n_ = _ivectorint(pointTags)
             ierr = c_int()
-            api__result__ = lib.gmshModelOccAddSpline(
+            api_result_ = lib.gmshModelOccAddSpline(
                 api_pointTags_, api_pointTags_n_,
                 c_int(tag),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccAddSpline returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addBSpline(pointTags, tag=-1, degree=3, weights=[], knots=[], multiplicities=[]):
@@ -4627,7 +4265,7 @@ class model:
             api_knots_, api_knots_n_ = _ivectordouble(knots)
             api_multiplicities_, api_multiplicities_n_ = _ivectorint(multiplicities)
             ierr = c_int()
-            api__result__ = lib.gmshModelOccAddBSpline(
+            api_result_ = lib.gmshModelOccAddBSpline(
                 api_pointTags_, api_pointTags_n_,
                 c_int(tag),
                 c_int(degree),
@@ -4636,10 +4274,8 @@ class model:
                 api_multiplicities_, api_multiplicities_n_,
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccAddBSpline returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addBezier(pointTags, tag=-1):
@@ -4654,15 +4290,13 @@ class model:
             """
             api_pointTags_, api_pointTags_n_ = _ivectorint(pointTags)
             ierr = c_int()
-            api__result__ = lib.gmshModelOccAddBezier(
+            api_result_ = lib.gmshModelOccAddBezier(
                 api_pointTags_, api_pointTags_n_,
                 c_int(tag),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccAddBezier returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addWire(curveTags, tag=-1, checkClosed=False):
@@ -4679,16 +4313,14 @@ class model:
             """
             api_curveTags_, api_curveTags_n_ = _ivectorint(curveTags)
             ierr = c_int()
-            api__result__ = lib.gmshModelOccAddWire(
+            api_result_ = lib.gmshModelOccAddWire(
                 api_curveTags_, api_curveTags_n_,
                 c_int(tag),
                 c_int(bool(checkClosed)),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccAddWire returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addCurveLoop(curveTags, tag=-1):
@@ -4706,15 +4338,13 @@ class model:
             """
             api_curveTags_, api_curveTags_n_ = _ivectorint(curveTags)
             ierr = c_int()
-            api__result__ = lib.gmshModelOccAddCurveLoop(
+            api_result_ = lib.gmshModelOccAddCurveLoop(
                 api_curveTags_, api_curveTags_n_,
                 c_int(tag),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccAddCurveLoop returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addRectangle(x, y, z, dx, dy, tag=-1, roundedRadius=0.):
@@ -4729,7 +4359,7 @@ class model:
             Return an integer value.
             """
             ierr = c_int()
-            api__result__ = lib.gmshModelOccAddRectangle(
+            api_result_ = lib.gmshModelOccAddRectangle(
                 c_double(x),
                 c_double(y),
                 c_double(z),
@@ -4739,10 +4369,8 @@ class model:
                 c_double(roundedRadius),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccAddRectangle returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addDisk(xc, yc, zc, rx, ry, tag=-1):
@@ -4756,7 +4384,7 @@ class model:
             Return an integer value.
             """
             ierr = c_int()
-            api__result__ = lib.gmshModelOccAddDisk(
+            api_result_ = lib.gmshModelOccAddDisk(
                 c_double(xc),
                 c_double(yc),
                 c_double(zc),
@@ -4765,10 +4393,8 @@ class model:
                 c_int(tag),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccAddDisk returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addPlaneSurface(wireTags, tag=-1):
@@ -4785,15 +4411,13 @@ class model:
             """
             api_wireTags_, api_wireTags_n_ = _ivectorint(wireTags)
             ierr = c_int()
-            api__result__ = lib.gmshModelOccAddPlaneSurface(
+            api_result_ = lib.gmshModelOccAddPlaneSurface(
                 api_wireTags_, api_wireTags_n_,
                 c_int(tag),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccAddPlaneSurface returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addSurfaceFilling(wireTag, tag=-1, pointTags=[]):
@@ -4809,16 +4433,14 @@ class model:
             """
             api_pointTags_, api_pointTags_n_ = _ivectorint(pointTags)
             ierr = c_int()
-            api__result__ = lib.gmshModelOccAddSurfaceFilling(
+            api_result_ = lib.gmshModelOccAddSurfaceFilling(
                 c_int(wireTag),
                 c_int(tag),
                 api_pointTags_, api_pointTags_n_,
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccAddSurfaceFilling returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addBSplineFilling(wireTag, tag=-1, type=""):
@@ -4836,16 +4458,14 @@ class model:
             Return an integer value.
             """
             ierr = c_int()
-            api__result__ = lib.gmshModelOccAddBSplineFilling(
+            api_result_ = lib.gmshModelOccAddBSplineFilling(
                 c_int(wireTag),
                 c_int(tag),
                 c_char_p(type.encode()),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccAddBSplineFilling returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addBezierFilling(wireTag, tag=-1, type=""):
@@ -4863,16 +4483,14 @@ class model:
             Return an integer value.
             """
             ierr = c_int()
-            api__result__ = lib.gmshModelOccAddBezierFilling(
+            api_result_ = lib.gmshModelOccAddBezierFilling(
                 c_int(wireTag),
                 c_int(tag),
                 c_char_p(type.encode()),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccAddBezierFilling returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addBSplineSurface(pointTags, numPointsU, tag=-1, degreeU=3, degreeV=3, weights=[], knotsU=[], knotsV=[], multiplicitiesU=[], multiplicitiesV=[]):
@@ -4895,7 +4513,7 @@ class model:
             api_multiplicitiesU_, api_multiplicitiesU_n_ = _ivectorint(multiplicitiesU)
             api_multiplicitiesV_, api_multiplicitiesV_n_ = _ivectorint(multiplicitiesV)
             ierr = c_int()
-            api__result__ = lib.gmshModelOccAddBSplineSurface(
+            api_result_ = lib.gmshModelOccAddBSplineSurface(
                 api_pointTags_, api_pointTags_n_,
                 c_int(numPointsU),
                 c_int(tag),
@@ -4908,10 +4526,8 @@ class model:
                 api_multiplicitiesV_, api_multiplicitiesV_n_,
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccAddBSplineSurface returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addBezierSurface(pointTags, numPointsU, tag=-1):
@@ -4927,16 +4543,14 @@ class model:
             """
             api_pointTags_, api_pointTags_n_ = _ivectorint(pointTags)
             ierr = c_int()
-            api__result__ = lib.gmshModelOccAddBezierSurface(
+            api_result_ = lib.gmshModelOccAddBezierSurface(
                 api_pointTags_, api_pointTags_n_,
                 c_int(numPointsU),
                 c_int(tag),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccAddBezierSurface returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addSurfaceLoop(surfaceTags, tag=-1, sewing=False):
@@ -4953,16 +4567,14 @@ class model:
             """
             api_surfaceTags_, api_surfaceTags_n_ = _ivectorint(surfaceTags)
             ierr = c_int()
-            api__result__ = lib.gmshModelOccAddSurfaceLoop(
+            api_result_ = lib.gmshModelOccAddSurfaceLoop(
                 api_surfaceTags_, api_surfaceTags_n_,
                 c_int(tag),
                 c_int(bool(sewing)),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccAddSurfaceLoop returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addVolume(shellTags, tag=-1):
@@ -4978,15 +4590,13 @@ class model:
             """
             api_shellTags_, api_shellTags_n_ = _ivectorint(shellTags)
             ierr = c_int()
-            api__result__ = lib.gmshModelOccAddVolume(
+            api_result_ = lib.gmshModelOccAddVolume(
                 api_shellTags_, api_shellTags_n_,
                 c_int(tag),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccAddVolume returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addSphere(xc, yc, zc, radius, tag=-1, angle1=-pi/2, angle2=pi/2, angle3=2*pi):
@@ -5002,7 +4612,7 @@ class model:
             Return an integer value.
             """
             ierr = c_int()
-            api__result__ = lib.gmshModelOccAddSphere(
+            api_result_ = lib.gmshModelOccAddSphere(
                 c_double(xc),
                 c_double(yc),
                 c_double(zc),
@@ -5013,10 +4623,8 @@ class model:
                 c_double(angle3),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccAddSphere returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addBox(x, y, z, dx, dy, dz, tag=-1):
@@ -5031,7 +4639,7 @@ class model:
             Return an integer value.
             """
             ierr = c_int()
-            api__result__ = lib.gmshModelOccAddBox(
+            api_result_ = lib.gmshModelOccAddBox(
                 c_double(x),
                 c_double(y),
                 c_double(z),
@@ -5041,10 +4649,8 @@ class model:
                 c_int(tag),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccAddBox returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addCylinder(x, y, z, dx, dy, dz, r, tag=-1, angle=2*pi):
@@ -5061,7 +4667,7 @@ class model:
             Return an integer value.
             """
             ierr = c_int()
-            api__result__ = lib.gmshModelOccAddCylinder(
+            api_result_ = lib.gmshModelOccAddCylinder(
                 c_double(x),
                 c_double(y),
                 c_double(z),
@@ -5073,10 +4679,8 @@ class model:
                 c_double(angle),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccAddCylinder returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addCone(x, y, z, dx, dy, dz, r1, r2, tag=-1, angle=2*pi):
@@ -5093,7 +4697,7 @@ class model:
             Return an integer value.
             """
             ierr = c_int()
-            api__result__ = lib.gmshModelOccAddCone(
+            api_result_ = lib.gmshModelOccAddCone(
                 c_double(x),
                 c_double(y),
                 c_double(z),
@@ -5106,10 +4710,8 @@ class model:
                 c_double(angle),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccAddCone returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addWedge(x, y, z, dx, dy, dz, tag=-1, ltx=0.):
@@ -5125,7 +4727,7 @@ class model:
             Return an integer value.
             """
             ierr = c_int()
-            api__result__ = lib.gmshModelOccAddWedge(
+            api_result_ = lib.gmshModelOccAddWedge(
                 c_double(x),
                 c_double(y),
                 c_double(z),
@@ -5136,10 +4738,8 @@ class model:
                 c_double(ltx),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccAddWedge returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addTorus(x, y, z, r1, r2, tag=-1, angle=2*pi):
@@ -5154,7 +4754,7 @@ class model:
             Return an integer value.
             """
             ierr = c_int()
-            api__result__ = lib.gmshModelOccAddTorus(
+            api_result_ = lib.gmshModelOccAddTorus(
                 c_double(x),
                 c_double(y),
                 c_double(z),
@@ -5164,10 +4764,8 @@ class model:
                 c_double(angle),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccAddTorus returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def addThruSections(wireTags, tag=-1, makeSolid=True, makeRuled=False, maxDegree=-1):
@@ -5196,9 +4794,7 @@ class model:
                 c_int(maxDegree),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccAddThruSections returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return _ovectorpair(api_outDimTags_, api_outDimTags_n_.value)
 
         @staticmethod
@@ -5225,9 +4821,7 @@ class model:
                 c_int(tag),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccAddThickSolid returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return _ovectorpair(api_outDimTags_, api_outDimTags_n_.value)
 
         @staticmethod
@@ -5259,9 +4853,7 @@ class model:
                 c_int(bool(recombine)),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccExtrude returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return _ovectorpair(api_outDimTags_, api_outDimTags_n_.value)
 
         @staticmethod
@@ -5300,9 +4892,7 @@ class model:
                 c_int(bool(recombine)),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccRevolve returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return _ovectorpair(api_outDimTags_, api_outDimTags_n_.value)
 
         @staticmethod
@@ -5324,9 +4914,7 @@ class model:
                 byref(api_outDimTags_), byref(api_outDimTags_n_),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccAddPipe returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return _ovectorpair(api_outDimTags_, api_outDimTags_n_.value)
 
         @staticmethod
@@ -5356,9 +4944,7 @@ class model:
                 c_int(bool(removeVolume)),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccFillet returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return _ovectorpair(api_outDimTags_, api_outDimTags_n_.value)
 
         @staticmethod
@@ -5392,9 +4978,7 @@ class model:
                 c_int(bool(removeVolume)),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccChamfer returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return _ovectorpair(api_outDimTags_, api_outDimTags_n_.value)
 
         @staticmethod
@@ -5425,9 +5009,7 @@ class model:
                 c_int(bool(removeTool)),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccFuse returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return (
                 _ovectorpair(api_outDimTags_, api_outDimTags_n_.value),
                 _ovectorvectorpair(api_outDimTagsMap_, api_outDimTagsMap_n_, api_outDimTagsMap_nn_))
@@ -5460,9 +5042,7 @@ class model:
                 c_int(bool(removeTool)),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccIntersect returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return (
                 _ovectorpair(api_outDimTags_, api_outDimTags_n_.value),
                 _ovectorvectorpair(api_outDimTagsMap_, api_outDimTagsMap_n_, api_outDimTagsMap_nn_))
@@ -5495,9 +5075,7 @@ class model:
                 c_int(bool(removeTool)),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccCut returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return (
                 _ovectorpair(api_outDimTags_, api_outDimTags_n_.value),
                 _ovectorvectorpair(api_outDimTagsMap_, api_outDimTagsMap_n_, api_outDimTagsMap_nn_))
@@ -5530,9 +5108,7 @@ class model:
                 c_int(bool(removeTool)),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccFragment returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return (
                 _ovectorpair(api_outDimTags_, api_outDimTags_n_.value),
                 _ovectorvectorpair(api_outDimTagsMap_, api_outDimTagsMap_n_, api_outDimTagsMap_nn_))
@@ -5553,9 +5129,7 @@ class model:
                 c_double(dz),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccTranslate returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def rotate(dimTags, x, y, z, ax, ay, az, angle):
@@ -5579,9 +5153,7 @@ class model:
                 c_double(angle),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccRotate returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def dilate(dimTags, x, y, z, a, b, c):
@@ -5604,9 +5176,7 @@ class model:
                 c_double(c),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccDilate returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def mirror(dimTags, a, b, c, d):
@@ -5626,9 +5196,7 @@ class model:
                 c_double(d),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccMirror returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def symmetrize(dimTags, a, b, c, d):
@@ -5650,9 +5218,7 @@ class model:
                 c_double(d),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccSymmetrize returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def affineTransform(dimTags, a):
@@ -5671,9 +5237,7 @@ class model:
                 api_a_, api_a_n_,
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccAffineTransform returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def copy(dimTags):
@@ -5692,9 +5256,7 @@ class model:
                 byref(api_outDimTags_), byref(api_outDimTags_n_),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccCopy returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return _ovectorpair(api_outDimTags_, api_outDimTags_n_.value)
 
         @staticmethod
@@ -5712,9 +5274,7 @@ class model:
                 c_int(bool(recursive)),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccRemove returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def removeAllDuplicates():
@@ -5729,9 +5289,7 @@ class model:
             lib.gmshModelOccRemoveAllDuplicates(
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccRemoveAllDuplicates returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def healShapes(dimTags=[], tolerance=1e-8, fixDegenerated=True, fixSmallEdges=True, fixSmallFaces=True, sewFaces=True, makeSolids=True):
@@ -5759,9 +5317,7 @@ class model:
                 c_int(bool(makeSolids)),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccHealShapes returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return _ovectorpair(api_outDimTags_, api_outDimTags_n_.value)
 
         @staticmethod
@@ -5786,9 +5342,7 @@ class model:
                 c_char_p(format.encode()),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccImportShapes returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return _ovectorpair(api_outDimTags_, api_outDimTags_n_.value)
 
         @staticmethod
@@ -5809,9 +5363,7 @@ class model:
                 c_int(dim),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccGetEntities returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return _ovectorpair(api_dimTags_, api_dimTags_n_.value)
 
         @staticmethod
@@ -5839,9 +5391,7 @@ class model:
                 c_int(dim),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccGetEntitiesInBoundingBox returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return _ovectorpair(api_tags_, api_tags_n_.value)
 
         @staticmethod
@@ -5872,9 +5422,7 @@ class model:
                 byref(api_zmax_),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccGetBoundingBox returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return (
                 api_xmin_.value,
                 api_ymin_.value,
@@ -5900,9 +5448,7 @@ class model:
                 byref(api_mass_),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccGetMass returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return api_mass_.value
 
         @staticmethod
@@ -5927,9 +5473,7 @@ class model:
                 byref(api_z_),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccGetCenterOfMass returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return (
                 api_x_.value,
                 api_y_.value,
@@ -5953,9 +5497,7 @@ class model:
                 byref(api_mat_), byref(api_mat_n_),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccGetMatrixOfInertia returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
             return _ovectordouble(api_mat_, api_mat_n_.value)
 
         @staticmethod
@@ -5969,14 +5511,12 @@ class model:
             Return an integer value.
             """
             ierr = c_int()
-            api__result__ = lib.gmshModelOccGetMaxTag(
+            api_result_ = lib.gmshModelOccGetMaxTag(
                 c_int(dim),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccGetMaxTag returned non-zero error code: ",
-                    ierr.value)
-            return api__result__
+                raise Exception(logger.getLastError())
+            return api_result_
 
         @staticmethod
         def setMaxTag(dim, maxTag):
@@ -5992,9 +5532,7 @@ class model:
                 c_int(maxTag),
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccSetMaxTag returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
         @staticmethod
         def synchronize():
@@ -6010,9 +5548,7 @@ class model:
             lib.gmshModelOccSynchronize(
                 byref(ierr))
             if ierr.value != 0:
-                raise ValueError(
-                    "gmshModelOccSynchronize returned non-zero error code: ",
-                    ierr.value)
+                raise Exception(logger.getLastError())
 
 
         class mesh:
@@ -6035,9 +5571,7 @@ class model:
                     c_double(size),
                     byref(ierr))
                 if ierr.value != 0:
-                    raise ValueError(
-                        "gmshModelOccMeshSetSize returned non-zero error code: ",
-                        ierr.value)
+                    raise Exception(logger.getLastError())
 
 
 class view:
@@ -6057,15 +5591,13 @@ class view:
         Return an integer value.
         """
         ierr = c_int()
-        api__result__ = lib.gmshViewAdd(
+        api_result_ = lib.gmshViewAdd(
             c_char_p(name.encode()),
             c_int(tag),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshViewAdd returned non-zero error code: ",
-                ierr.value)
-        return api__result__
+            raise Exception(logger.getLastError())
+        return api_result_
 
     @staticmethod
     def remove(tag):
@@ -6079,9 +5611,7 @@ class view:
             c_int(tag),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshViewRemove returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
     @staticmethod
     def getIndex(tag):
@@ -6095,14 +5625,12 @@ class view:
         Return an integer value.
         """
         ierr = c_int()
-        api__result__ = lib.gmshViewGetIndex(
+        api_result_ = lib.gmshViewGetIndex(
             c_int(tag),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshViewGetIndex returned non-zero error code: ",
-                ierr.value)
-        return api__result__
+            raise Exception(logger.getLastError())
+        return api_result_
 
     @staticmethod
     def getTags():
@@ -6119,9 +5647,7 @@ class view:
             byref(api_tags_), byref(api_tags_n_),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshViewGetTags returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return _ovectorint(api_tags_, api_tags_n_.value)
 
     @staticmethod
@@ -6157,9 +5683,7 @@ class view:
             c_int(partition),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshViewAddModelData returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
     @staticmethod
     def addHomogeneousModelData(tag, step, modelName, dataType, tags, data, time=0., numComponents=-1, partition=0):
@@ -6187,9 +5711,7 @@ class view:
             c_int(partition),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshViewAddHomogeneousModelData returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
     @staticmethod
     def getModelData(tag, step):
@@ -6219,9 +5741,7 @@ class view:
             byref(api_numComponents_),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshViewGetModelData returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return (
             _ostring(api_dataType_),
             _ovectorsize(api_tags_, api_tags_n_.value),
@@ -6257,9 +5777,7 @@ class view:
             byref(api_numComponents_),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshViewGetHomogeneousModelData returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return (
             _ostring(api_dataType_),
             _ovectorsize(api_tags_, api_tags_n_.value),
@@ -6286,9 +5804,7 @@ class view:
             api_data_, api_data_n_,
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshViewAddListData returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
     @staticmethod
     def getListData(tag):
@@ -6312,9 +5828,7 @@ class view:
             byref(api_data_), byref(api_data_n_), byref(api_data_nn_),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshViewGetListData returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return (
             _ovectorstring(api_dataType_, api_dataType_n_.value),
             _ovectorint(api_numElements_, api_numElements_n_.value),
@@ -6343,9 +5857,7 @@ class view:
             api_style_, api_style_n_,
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshViewAddListDataString returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
     @staticmethod
     def getListDataStrings(tag, dim):
@@ -6370,9 +5882,7 @@ class view:
             byref(api_style_), byref(api_style_n_),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshViewGetListDataStrings returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return (
             _ovectordouble(api_coord_, api_coord_n_.value),
             _ovectorstring(api_data_, api_data_n_.value),
@@ -6391,16 +5901,14 @@ class view:
         Return an integer value.
         """
         ierr = c_int()
-        api__result__ = lib.gmshViewAddAlias(
+        api_result_ = lib.gmshViewAddAlias(
             c_int(refTag),
             c_int(bool(copyOptions)),
             c_int(tag),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshViewAddAlias returned non-zero error code: ",
-                ierr.value)
-        return api__result__
+            raise Exception(logger.getLastError())
+        return api_result_
 
     @staticmethod
     def copyOptions(refTag, tag):
@@ -6416,9 +5924,7 @@ class view:
             c_int(tag),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshViewCopyOptions returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
     @staticmethod
     def combine(what, how, remove=True, copyOptions=True):
@@ -6438,9 +5944,7 @@ class view:
             c_int(bool(copyOptions)),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshViewCombine returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
     @staticmethod
     def probe(tag, x, y, z, step=-1, numComp=-1, gradient=False, tolerance=0., xElemCoord=[], yElemCoord=[], zElemCoord=[]):
@@ -6477,9 +5981,7 @@ class view:
             api_zElemCoord_, api_zElemCoord_n_,
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshViewProbe returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return _ovectordouble(api_value_, api_value_n_.value)
 
     @staticmethod
@@ -6497,9 +5999,7 @@ class view:
             c_int(bool(append)),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshViewWrite returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
 
 class plugin:
@@ -6521,9 +6021,7 @@ class plugin:
             c_double(value),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshPluginSetNumber returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
     @staticmethod
     def setString(name, option, value):
@@ -6539,9 +6037,7 @@ class plugin:
             c_char_p(value.encode()),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshPluginSetString returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
     @staticmethod
     def run(name):
@@ -6555,9 +6051,7 @@ class plugin:
             c_char_p(name.encode()),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshPluginRun returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
 
 class graphics:
@@ -6576,9 +6070,7 @@ class graphics:
         lib.gmshGraphicsDraw(
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshGraphicsDraw returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
 
 class fltk:
@@ -6598,9 +6090,7 @@ class fltk:
         lib.gmshFltkInitialize(
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshFltkInitialize returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
     @staticmethod
     def wait(time=-1.):
@@ -6616,9 +6106,7 @@ class fltk:
             c_double(time),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshFltkWait returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
     @staticmethod
     def update():
@@ -6634,9 +6122,7 @@ class fltk:
         lib.gmshFltkUpdate(
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshFltkUpdate returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
     @staticmethod
     def awake(action=""):
@@ -6652,9 +6138,7 @@ class fltk:
             c_char_p(action.encode()),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshFltkAwake returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
     @staticmethod
     def lock():
@@ -6667,9 +6151,7 @@ class fltk:
         lib.gmshFltkLock(
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshFltkLock returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
     @staticmethod
     def unlock():
@@ -6682,9 +6164,7 @@ class fltk:
         lib.gmshFltkUnlock(
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshFltkUnlock returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
     @staticmethod
     def run():
@@ -6699,9 +6179,7 @@ class fltk:
         lib.gmshFltkRun(
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshFltkRun returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
     @staticmethod
     def isAvailable():
@@ -6714,13 +6192,11 @@ class fltk:
         Return an integer value.
         """
         ierr = c_int()
-        api__result__ = lib.gmshFltkIsAvailable(
+        api_result_ = lib.gmshFltkIsAvailable(
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshFltkIsAvailable returned non-zero error code: ",
-                ierr.value)
-        return api__result__
+            raise Exception(logger.getLastError())
+        return api_result_
 
     @staticmethod
     def selectEntities(dim=-1):
@@ -6734,16 +6210,14 @@ class fltk:
         """
         api_dimTags_, api_dimTags_n_ = POINTER(c_int)(), c_size_t()
         ierr = c_int()
-        api__result__ = lib.gmshFltkSelectEntities(
+        api_result_ = lib.gmshFltkSelectEntities(
             byref(api_dimTags_), byref(api_dimTags_n_),
             c_int(dim),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshFltkSelectEntities returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return (
-            api__result__,
+            api_result_,
             _ovectorpair(api_dimTags_, api_dimTags_n_.value))
 
     @staticmethod
@@ -6757,15 +6231,13 @@ class fltk:
         """
         api_elementTags_, api_elementTags_n_ = POINTER(c_size_t)(), c_size_t()
         ierr = c_int()
-        api__result__ = lib.gmshFltkSelectElements(
+        api_result_ = lib.gmshFltkSelectElements(
             byref(api_elementTags_), byref(api_elementTags_n_),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshFltkSelectElements returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return (
-            api__result__,
+            api_result_,
             _ovectorsize(api_elementTags_, api_elementTags_n_.value))
 
     @staticmethod
@@ -6779,15 +6251,13 @@ class fltk:
         """
         api_viewTags_, api_viewTags_n_ = POINTER(c_int)(), c_size_t()
         ierr = c_int()
-        api__result__ = lib.gmshFltkSelectViews(
+        api_result_ = lib.gmshFltkSelectViews(
             byref(api_viewTags_), byref(api_viewTags_n_),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshFltkSelectViews returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return (
-            api__result__,
+            api_result_,
             _ovectorint(api_viewTags_, api_viewTags_n_.value))
 
 
@@ -6809,9 +6279,7 @@ class onelab:
             c_char_p(format.encode()),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshOnelabSet returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
     @staticmethod
     def get(name="", format="json"):
@@ -6831,9 +6299,7 @@ class onelab:
             c_char_p(format.encode()),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshOnelabGet returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return _ostring(api_data_)
 
     @staticmethod
@@ -6852,9 +6318,7 @@ class onelab:
             api_value_, api_value_n_,
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshOnelabSetNumber returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
     @staticmethod
     def setString(name, value):
@@ -6872,9 +6336,7 @@ class onelab:
             api_value_, api_value_n_,
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshOnelabSetString returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
     @staticmethod
     def getNumber(name):
@@ -6893,9 +6355,7 @@ class onelab:
             byref(api_value_), byref(api_value_n_),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshOnelabGetNumber returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return _ovectordouble(api_value_, api_value_n_.value)
 
     @staticmethod
@@ -6915,9 +6375,7 @@ class onelab:
             byref(api_value_), byref(api_value_n_),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshOnelabGetString returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return _ovectorstring(api_value_, api_value_n_.value)
 
     @staticmethod
@@ -6932,9 +6390,7 @@ class onelab:
             c_char_p(name.encode()),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshOnelabClear returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
     @staticmethod
     def run(name="", command=""):
@@ -6951,9 +6407,7 @@ class onelab:
             c_char_p(command.encode()),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshOnelabRun returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
 
 class logger:
@@ -6974,9 +6428,7 @@ class logger:
             c_char_p(level.encode()),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshLoggerWrite returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
     @staticmethod
     def start():
@@ -6989,9 +6441,7 @@ class logger:
         lib.gmshLoggerStart(
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshLoggerStart returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
     @staticmethod
     def get():
@@ -7008,9 +6458,7 @@ class logger:
             byref(api_log_), byref(api_log_n_),
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshLoggerGet returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
         return _ovectorstring(api_log_, api_log_n_.value)
 
     @staticmethod
@@ -7024,9 +6472,7 @@ class logger:
         lib.gmshLoggerStop(
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshLoggerStop returned non-zero error code: ",
-                ierr.value)
+            raise Exception(logger.getLastError())
 
     @staticmethod
     def getWallTime():
@@ -7038,13 +6484,11 @@ class logger:
         Return a floating point value.
         """
         ierr = c_int()
-        api__result__ = lib.gmshLoggerGetWallTime(
+        api_result_ = lib.gmshLoggerGetWallTime(
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshLoggerGetWallTime returned non-zero error code: ",
-                ierr.value)
-        return api__result__
+            raise Exception(logger.getLastError())
+        return api_result_
 
     @staticmethod
     def getCpuTime():
@@ -7056,10 +6500,26 @@ class logger:
         Return a floating point value.
         """
         ierr = c_int()
-        api__result__ = lib.gmshLoggerGetCpuTime(
+        api_result_ = lib.gmshLoggerGetCpuTime(
             byref(ierr))
         if ierr.value != 0:
-            raise ValueError(
-                "gmshLoggerGetCpuTime returned non-zero error code: ",
-                ierr.value)
-        return api__result__
+            raise Exception(logger.getLastError())
+        return api_result_
+
+    @staticmethod
+    def getLastError():
+        """
+        gmsh.logger.getLastError()
+
+        Return last error message, if any.
+
+        Return `error'.
+        """
+        api_error_ = c_char_p()
+        ierr = c_int()
+        lib.gmshLoggerGetLastError(
+            byref(api_error_),
+            byref(ierr))
+        if ierr.value != 0:
+            raise Exception('Could not get last error')
+        return _ostring(api_error_)
diff --git a/api/gmshc.cpp b/api/gmshc.cpp
index f817815818..1e58775dc5 100644
--- a/api/gmshc.cpp
+++ b/api/gmshc.cpp
@@ -76,8 +76,8 @@ GMSH_API void gmshInitialize(int argc, char ** argv, const int readConfigFiles,
   try {
     gmsh::initialize(argc, argv, readConfigFiles);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -87,8 +87,8 @@ GMSH_API void gmshFinalize(int * ierr)
   try {
     gmsh::finalize();
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -98,8 +98,8 @@ GMSH_API void gmshOpen(const char * fileName, int * ierr)
   try {
     gmsh::open(fileName);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -109,8 +109,8 @@ GMSH_API void gmshMerge(const char * fileName, int * ierr)
   try {
     gmsh::merge(fileName);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -120,8 +120,8 @@ GMSH_API void gmshWrite(const char * fileName, int * ierr)
   try {
     gmsh::write(fileName);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -131,8 +131,8 @@ GMSH_API void gmshClear(int * ierr)
   try {
     gmsh::clear();
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -142,8 +142,8 @@ GMSH_API void gmshOptionSetNumber(const char * name, const double value, int * i
   try {
     gmsh::option::setNumber(name, value);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -153,8 +153,8 @@ GMSH_API void gmshOptionGetNumber(const char * name, double * value, int * ierr)
   try {
     gmsh::option::getNumber(name, *value);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -164,8 +164,8 @@ GMSH_API void gmshOptionSetString(const char * name, const char * value, int * i
   try {
     gmsh::option::setString(name, value);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -177,8 +177,8 @@ GMSH_API void gmshOptionGetString(const char * name, char ** value, int * ierr)
     gmsh::option::getString(name, api_value_);
     *value = strdup(api_value_.c_str());
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -188,8 +188,8 @@ GMSH_API void gmshOptionSetColor(const char * name, const int r, const int g, co
   try {
     gmsh::option::setColor(name, r, g, b, a);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -199,8 +199,8 @@ GMSH_API void gmshOptionGetColor(const char * name, int * r, int * g, int * b, i
   try {
     gmsh::option::getColor(name, *r, *g, *b, *a);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -210,8 +210,8 @@ GMSH_API void gmshModelAdd(const char * name, int * ierr)
   try {
     gmsh::model::add(name);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -221,8 +221,8 @@ GMSH_API void gmshModelRemove(int * ierr)
   try {
     gmsh::model::remove();
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -234,8 +234,8 @@ GMSH_API void gmshModelList(char *** names, size_t * names_n, int * ierr)
     gmsh::model::list(api_names_);
     vectorstring2charptrptr(api_names_, names, names_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -247,8 +247,8 @@ GMSH_API void gmshModelGetCurrent(char ** name, int * ierr)
     gmsh::model::getCurrent(api_name_);
     *name = strdup(api_name_.c_str());
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -258,8 +258,8 @@ GMSH_API void gmshModelSetCurrent(const char * name, int * ierr)
   try {
     gmsh::model::setCurrent(name);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -271,8 +271,8 @@ GMSH_API void gmshModelGetEntities(int ** dimTags, size_t * dimTags_n, const int
     gmsh::model::getEntities(api_dimTags_, dim);
     vectorpair2intptr(api_dimTags_, dimTags, dimTags_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -282,8 +282,8 @@ GMSH_API void gmshModelSetEntityName(const int dim, const int tag, const char *
   try {
     gmsh::model::setEntityName(dim, tag, name);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -295,8 +295,8 @@ GMSH_API void gmshModelGetEntityName(const int dim, const int tag, char ** name,
     gmsh::model::getEntityName(dim, tag, api_name_);
     *name = strdup(api_name_.c_str());
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -308,8 +308,8 @@ GMSH_API void gmshModelGetPhysicalGroups(int ** dimTags, size_t * dimTags_n, con
     gmsh::model::getPhysicalGroups(api_dimTags_, dim);
     vectorpair2intptr(api_dimTags_, dimTags, dimTags_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -321,8 +321,8 @@ GMSH_API void gmshModelGetEntitiesForPhysicalGroup(const int dim, const int tag,
     gmsh::model::getEntitiesForPhysicalGroup(dim, tag, api_tags_);
     vector2ptr(api_tags_, tags, tags_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -334,8 +334,8 @@ GMSH_API void gmshModelGetPhysicalGroupsForEntity(const int dim, const int tag,
     gmsh::model::getPhysicalGroupsForEntity(dim, tag, api_physicalTags_);
     vector2ptr(api_physicalTags_, physicalTags, physicalTags_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -347,8 +347,8 @@ GMSH_API int gmshModelAddPhysicalGroup(const int dim, int * tags, size_t tags_n,
     std::vector<int> api_tags_(tags, tags + tags_n);
     result_api_ = gmsh::model::addPhysicalGroup(dim, api_tags_, tag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -359,8 +359,8 @@ GMSH_API void gmshModelSetPhysicalName(const int dim, const int tag, const char
   try {
     gmsh::model::setPhysicalName(dim, tag, name);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -372,8 +372,8 @@ GMSH_API void gmshModelGetPhysicalName(const int dim, const int tag, char ** nam
     gmsh::model::getPhysicalName(dim, tag, api_name_);
     *name = strdup(api_name_.c_str());
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -390,8 +390,8 @@ GMSH_API void gmshModelGetBoundary(int * dimTags, size_t dimTags_n, int ** outDi
     gmsh::model::getBoundary(api_dimTags_, api_outDimTags_, combined, oriented, recursive);
     vectorpair2intptr(api_outDimTags_, outDimTags, outDimTags_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -403,8 +403,8 @@ GMSH_API void gmshModelGetEntitiesInBoundingBox(const double xmin, const double
     gmsh::model::getEntitiesInBoundingBox(xmin, ymin, zmin, xmax, ymax, zmax, api_tags_, dim);
     vectorpair2intptr(api_tags_, tags, tags_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -414,8 +414,8 @@ GMSH_API void gmshModelGetBoundingBox(const int dim, const int tag, double * xmi
   try {
     gmsh::model::getBoundingBox(dim, tag, *xmin, *ymin, *zmin, *xmax, *ymax, *zmax);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -426,8 +426,8 @@ GMSH_API int gmshModelGetDimension(int * ierr)
   try {
     result_api_ = gmsh::model::getDimension();
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -440,8 +440,8 @@ GMSH_API int gmshModelAddDiscreteEntity(const int dim, const int tag, int * boun
     std::vector<int> api_boundary_(boundary, boundary + boundary_n);
     result_api_ = gmsh::model::addDiscreteEntity(dim, tag, api_boundary_);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -457,8 +457,8 @@ GMSH_API void gmshModelRemoveEntities(int * dimTags, size_t dimTags_n, const int
     }
     gmsh::model::removeEntities(api_dimTags_, recursive);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -468,8 +468,8 @@ GMSH_API void gmshModelRemoveEntityName(const char * name, int * ierr)
   try {
     gmsh::model::removeEntityName(name);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -484,8 +484,8 @@ GMSH_API void gmshModelRemovePhysicalGroups(int * dimTags, size_t dimTags_n, int
     }
     gmsh::model::removePhysicalGroups(api_dimTags_);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -495,8 +495,8 @@ GMSH_API void gmshModelRemovePhysicalName(const char * name, int * ierr)
   try {
     gmsh::model::removePhysicalName(name);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -508,8 +508,8 @@ GMSH_API void gmshModelGetType(const int dim, const int tag, char ** entityType,
     gmsh::model::getType(dim, tag, api_entityType_);
     *entityType = strdup(api_entityType_.c_str());
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -519,8 +519,8 @@ GMSH_API void gmshModelGetParent(const int dim, const int tag, int * parentDim,
   try {
     gmsh::model::getParent(dim, tag, *parentDim, *parentTag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -532,8 +532,8 @@ GMSH_API void gmshModelGetPartitions(const int dim, const int tag, int ** partit
     gmsh::model::getPartitions(dim, tag, api_partitions_);
     vector2ptr(api_partitions_, partitions, partitions_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -546,8 +546,8 @@ GMSH_API void gmshModelGetValue(const int dim, const int tag, double * parametri
     gmsh::model::getValue(dim, tag, api_parametricCoord_, api_coord_);
     vector2ptr(api_coord_, coord, coord_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -560,8 +560,8 @@ GMSH_API void gmshModelGetDerivative(const int dim, const int tag, double * para
     gmsh::model::getDerivative(dim, tag, api_parametricCoord_, api_derivatives_);
     vector2ptr(api_derivatives_, derivatives, derivatives_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -574,8 +574,8 @@ GMSH_API void gmshModelGetCurvature(const int dim, const int tag, double * param
     gmsh::model::getCurvature(dim, tag, api_parametricCoord_, api_curvatures_);
     vector2ptr(api_curvatures_, curvatures, curvatures_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -594,8 +594,8 @@ GMSH_API void gmshModelGetPrincipalCurvatures(const int tag, double * parametric
     vector2ptr(api_directionMax_, directionMax, directionMax_n);
     vector2ptr(api_directionMin_, directionMin, directionMin_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -608,8 +608,8 @@ GMSH_API void gmshModelGetNormal(const int tag, double * parametricCoord, size_t
     gmsh::model::getNormal(tag, api_parametricCoord_, api_normals_);
     vector2ptr(api_normals_, normals, normals_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -622,8 +622,8 @@ GMSH_API void gmshModelGetParametrization(const int dim, const int tag, double *
     gmsh::model::getParametrization(dim, tag, api_coord_, api_parametricCoord_);
     vector2ptr(api_parametricCoord_, parametricCoord, parametricCoord_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -637,8 +637,8 @@ GMSH_API void gmshModelGetParametrizationBounds(const int dim, const int tag, do
     vector2ptr(api_min_, min, min_n);
     vector2ptr(api_max_, max, max_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -650,8 +650,8 @@ GMSH_API int gmshModelIsInside(const int dim, const int tag, double * parametric
     std::vector<double> api_parametricCoord_(parametricCoord, parametricCoord + parametricCoord_n);
     result_api_ = gmsh::model::isInside(dim, tag, api_parametricCoord_);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -667,8 +667,8 @@ GMSH_API void gmshModelGetClosestPoint(const int dim, const int tag, double * co
     vector2ptr(api_closestCoord_, closestCoord, closestCoord_n);
     vector2ptr(api_parametricCoord_, parametricCoord, parametricCoord_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -681,8 +681,8 @@ GMSH_API void gmshModelReparametrizeOnSurface(const int dim, const int tag, doub
     gmsh::model::reparametrizeOnSurface(dim, tag, api_parametricCoord_, surfaceTag, api_surfaceParametricCoord_, which);
     vector2ptr(api_surfaceParametricCoord_, surfaceParametricCoord, surfaceParametricCoord_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -697,8 +697,8 @@ GMSH_API void gmshModelSetVisibility(int * dimTags, size_t dimTags_n, const int
     }
     gmsh::model::setVisibility(api_dimTags_, value, recursive);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -708,8 +708,8 @@ GMSH_API void gmshModelGetVisibility(const int dim, const int tag, int * value,
   try {
     gmsh::model::getVisibility(dim, tag, *value);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -724,8 +724,8 @@ GMSH_API void gmshModelSetColor(int * dimTags, size_t dimTags_n, const int r, co
     }
     gmsh::model::setColor(api_dimTags_, r, g, b, a, recursive);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -735,8 +735,8 @@ GMSH_API void gmshModelGetColor(const int dim, const int tag, int * r, int * g,
   try {
     gmsh::model::getColor(dim, tag, *r, *g, *b, *a);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -746,8 +746,8 @@ GMSH_API void gmshModelSetCoordinates(const int tag, const double x, const doubl
   try {
     gmsh::model::setCoordinates(tag, x, y, z);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -757,8 +757,8 @@ GMSH_API void gmshModelMeshGenerate(const int dim, int * ierr)
   try {
     gmsh::model::mesh::generate(dim);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -768,8 +768,8 @@ GMSH_API void gmshModelMeshPartition(const int numPart, int * ierr)
   try {
     gmsh::model::mesh::partition(numPart);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -779,8 +779,8 @@ GMSH_API void gmshModelMeshUnpartition(int * ierr)
   try {
     gmsh::model::mesh::unpartition();
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -795,8 +795,8 @@ GMSH_API void gmshModelMeshOptimize(const char * method, const int force, const
     }
     gmsh::model::mesh::optimize(method, force, niter, api_dimTags_);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -806,8 +806,8 @@ GMSH_API void gmshModelMeshRecombine(int * ierr)
   try {
     gmsh::model::mesh::recombine();
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -817,8 +817,8 @@ GMSH_API void gmshModelMeshRefine(int * ierr)
   try {
     gmsh::model::mesh::refine();
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -828,8 +828,8 @@ GMSH_API void gmshModelMeshSetOrder(const int order, int * ierr)
   try {
     gmsh::model::mesh::setOrder(order);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -841,8 +841,8 @@ GMSH_API void gmshModelMeshGetLastEntityError(int ** dimTags, size_t * dimTags_n
     gmsh::model::mesh::getLastEntityError(api_dimTags_);
     vectorpair2intptr(api_dimTags_, dimTags, dimTags_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -854,8 +854,8 @@ GMSH_API void gmshModelMeshGetLastNodeError(size_t ** nodeTags, size_t * nodeTag
     gmsh::model::mesh::getLastNodeError(api_nodeTags_);
     vector2ptr(api_nodeTags_, nodeTags, nodeTags_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -870,8 +870,8 @@ GMSH_API void gmshModelMeshClear(int * dimTags, size_t dimTags_n, int * ierr)
     }
     gmsh::model::mesh::clear(api_dimTags_);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -887,8 +887,8 @@ GMSH_API void gmshModelMeshGetNodes(size_t ** nodeTags, size_t * nodeTags_n, dou
     vector2ptr(api_coord_, coord, coord_n);
     vector2ptr(api_parametricCoord_, parametricCoord, parametricCoord_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -904,8 +904,8 @@ GMSH_API void gmshModelMeshGetNodesByElementType(const int elementType, size_t *
     vector2ptr(api_coord_, coord, coord_n);
     vector2ptr(api_parametricCoord_, parametricCoord, parametricCoord_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -919,8 +919,8 @@ GMSH_API void gmshModelMeshGetNode(const size_t nodeTag, double ** coord, size_t
     vector2ptr(api_coord_, coord, coord_n);
     vector2ptr(api_parametricCoord_, parametricCoord, parametricCoord_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -932,8 +932,8 @@ GMSH_API void gmshModelMeshSetNode(const size_t nodeTag, double * coord, size_t
     std::vector<double> api_parametricCoord_(parametricCoord, parametricCoord + parametricCoord_n);
     gmsh::model::mesh::setNode(nodeTag, api_coord_, api_parametricCoord_);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -943,8 +943,8 @@ GMSH_API void gmshModelMeshRebuildNodeCache(const int onlyIfNecessary, int * ier
   try {
     gmsh::model::mesh::rebuildNodeCache(onlyIfNecessary);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -954,8 +954,8 @@ GMSH_API void gmshModelMeshRebuildElementCache(const int onlyIfNecessary, int *
   try {
     gmsh::model::mesh::rebuildElementCache(onlyIfNecessary);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -969,8 +969,8 @@ GMSH_API void gmshModelMeshGetNodesForPhysicalGroup(const int dim, const int tag
     vector2ptr(api_nodeTags_, nodeTags, nodeTags_n);
     vector2ptr(api_coord_, coord, coord_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -983,8 +983,8 @@ GMSH_API void gmshModelMeshAddNodes(const int dim, const int tag, size_t * nodeT
     std::vector<double> api_parametricCoord_(parametricCoord, parametricCoord + parametricCoord_n);
     gmsh::model::mesh::addNodes(dim, tag, api_nodeTags_, api_coord_, api_parametricCoord_);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -994,8 +994,8 @@ GMSH_API void gmshModelMeshReclassifyNodes(int * ierr)
   try {
     gmsh::model::mesh::reclassifyNodes();
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1005,8 +1005,8 @@ GMSH_API void gmshModelMeshRelocateNodes(const int dim, const int tag, int * ier
   try {
     gmsh::model::mesh::relocateNodes(dim, tag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1022,8 +1022,8 @@ GMSH_API void gmshModelMeshGetElements(int ** elementTypes, size_t * elementType
     vectorvector2ptrptr(api_elementTags_, elementTags, elementTags_n, elementTags_nn);
     vectorvector2ptrptr(api_nodeTags_, nodeTags, nodeTags_n, nodeTags_nn);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1035,8 +1035,8 @@ GMSH_API void gmshModelMeshGetElement(const size_t elementTag, int * elementType
     gmsh::model::mesh::getElement(elementTag, *elementType, api_nodeTags_);
     vector2ptr(api_nodeTags_, nodeTags, nodeTags_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1048,8 +1048,8 @@ GMSH_API void gmshModelMeshGetElementByCoordinates(const double x, const double
     gmsh::model::mesh::getElementByCoordinates(x, y, z, *elementTag, *elementType, api_nodeTags_, *u, *v, *w, dim, strict);
     vector2ptr(api_nodeTags_, nodeTags, nodeTags_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1061,8 +1061,8 @@ GMSH_API void gmshModelMeshGetElementsByCoordinates(const double x, const double
     gmsh::model::mesh::getElementsByCoordinates(x, y, z, api_elementTags_, dim, strict);
     vector2ptr(api_elementTags_, elementTags, elementTags_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1072,8 +1072,8 @@ GMSH_API void gmshModelMeshGetLocalCoordinatesInElement(const size_t elementTag,
   try {
     gmsh::model::mesh::getLocalCoordinatesInElement(elementTag, x, y, z, *u, *v, *w);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1085,8 +1085,8 @@ GMSH_API void gmshModelMeshGetElementTypes(int ** elementTypes, size_t * element
     gmsh::model::mesh::getElementTypes(api_elementTypes_, dim, tag);
     vector2ptr(api_elementTypes_, elementTypes, elementTypes_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1097,8 +1097,8 @@ GMSH_API int gmshModelMeshGetElementType(const char * familyName, const int orde
   try {
     result_api_ = gmsh::model::mesh::getElementType(familyName, order, serendip);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -1113,8 +1113,8 @@ GMSH_API void gmshModelMeshGetElementProperties(const int elementType, char ** e
     *elementName = strdup(api_elementName_.c_str());
     vector2ptr(api_localNodeCoord_, localNodeCoord, localNodeCoord_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1128,8 +1128,8 @@ GMSH_API void gmshModelMeshGetElementsByType(const int elementType, size_t ** el
     vector2ptr(api_elementTags_, elementTags, elementTags_n);
     vector2ptr(api_nodeTags_, nodeTags, nodeTags_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1143,8 +1143,8 @@ GMSH_API void gmshModelMeshPreallocateElementsByType(const int elementType, cons
     vector2ptr(api_elementTags_, elementTags, elementTags_n);
     vector2ptr(api_nodeTags_, nodeTags, nodeTags_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1161,8 +1161,8 @@ GMSH_API void gmshModelMeshAddElements(const int dim, const int tag, int * eleme
       api_nodeTags_[i] = std::vector<std::size_t>(nodeTags[i], nodeTags[i] + nodeTags_n[i]);
     gmsh::model::mesh::addElements(dim, tag, api_elementTypes_, api_elementTags_, api_nodeTags_);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1174,8 +1174,8 @@ GMSH_API void gmshModelMeshAddElementsByType(const int tag, const int elementTyp
     std::vector<std::size_t> api_nodeTags_(nodeTags, nodeTags + nodeTags_n);
     gmsh::model::mesh::addElementsByType(tag, elementType, api_elementTags_, api_nodeTags_);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1189,8 +1189,8 @@ GMSH_API void gmshModelMeshGetIntegrationPoints(const int elementType, const cha
     vector2ptr(api_localCoord_, localCoord, localCoord_n);
     vector2ptr(api_weights_, weights, weights_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1207,8 +1207,8 @@ GMSH_API void gmshModelMeshGetJacobians(const int elementType, double * localCoo
     vector2ptr(api_determinants_, determinants, determinants_n);
     vector2ptr(api_coord_, coord, coord_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1224,8 +1224,8 @@ GMSH_API void gmshModelMeshPreallocateJacobians(const int elementType, const int
     vector2ptr(api_determinants_, determinants, determinants_n);
     vector2ptr(api_coord_, coord, coord_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1242,8 +1242,8 @@ GMSH_API void gmshModelMeshGetJacobian(const size_t elementTag, double * localCo
     vector2ptr(api_determinants_, determinants, determinants_n);
     vector2ptr(api_coord_, coord, coord_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1257,8 +1257,8 @@ GMSH_API void gmshModelMeshGetBasisFunctions(const int elementType, double * loc
     gmsh::model::mesh::getBasisFunctions(elementType, api_localCoord_, functionSpaceType, *numComponents, api_basisFunctions_, *numOrientations, api_wantedOrientations_);
     vector2ptr(api_basisFunctions_, basisFunctions, basisFunctions_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1270,8 +1270,8 @@ GMSH_API void gmshModelMeshGetBasisFunctionsOrientationForElements(const int ele
     gmsh::model::mesh::getBasisFunctionsOrientationForElements(elementType, functionSpaceType, api_basisFunctionsOrientation_, tag, task, numTasks);
     vector2ptr(api_basisFunctionsOrientation_, basisFunctionsOrientation, basisFunctionsOrientation_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1281,8 +1281,8 @@ GMSH_API void gmshModelMeshGetBasisFunctionsOrientationForElement(const size_t e
   try {
     gmsh::model::mesh::getBasisFunctionsOrientationForElement(elementTag, functionSpaceType, *basisFunctionsOrientation);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1293,8 +1293,8 @@ GMSH_API int gmshModelMeshGetNumberOfOrientations(const int elementType, const c
   try {
     result_api_ = gmsh::model::mesh::getNumberOfOrientations(elementType, functionSpaceType);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -1307,8 +1307,8 @@ GMSH_API void gmshModelMeshPreallocateBasisFunctionsOrientationForElements(const
     gmsh::model::mesh::preallocateBasisFunctionsOrientationForElements(elementType, api_basisFunctionsOrientation_, tag);
     vector2ptr(api_basisFunctionsOrientation_, basisFunctionsOrientation, basisFunctionsOrientation_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1321,8 +1321,8 @@ GMSH_API void gmshModelMeshGetEdgeNumber(int * edgeNodes, size_t edgeNodes_n, in
     gmsh::model::mesh::getEdgeNumber(api_edgeNodes_, api_edgeNum_);
     vector2ptr(api_edgeNum_, edgeNum, edgeNum_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1334,8 +1334,8 @@ GMSH_API void gmshModelMeshGetLocalMultipliersForHcurl0(const int elementType, i
     gmsh::model::mesh::getLocalMultipliersForHcurl0(elementType, api_localMultipliers_, tag);
     vector2ptr(api_localMultipliers_, localMultipliers, localMultipliers_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1349,8 +1349,8 @@ GMSH_API void gmshModelMeshGetKeysForElements(const int elementType, const char
     vectorpair2intptr(api_keys_, keys, keys_n);
     vector2ptr(api_coord_, coord, coord_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1364,8 +1364,8 @@ GMSH_API void gmshModelMeshGetKeysForElement(const size_t elementTag, const char
     vectorpair2intptr(api_keys_, keys, keys_n);
     vector2ptr(api_coord_, coord, coord_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1376,8 +1376,8 @@ GMSH_API int gmshModelMeshGetNumberOfKeysForElements(const int elementType, cons
   try {
     result_api_ = gmsh::model::mesh::getNumberOfKeysForElements(elementType, functionSpaceType);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -1395,8 +1395,8 @@ GMSH_API void gmshModelMeshGetInformationForElements(int * keys, size_t keys_n,
     gmsh::model::mesh::getInformationForElements(api_keys_, elementType, functionSpaceType, api_infoKeys_);
     vectorpair2intptr(api_infoKeys_, infoKeys, infoKeys_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1408,8 +1408,8 @@ GMSH_API void gmshModelMeshGetBarycenters(const int elementType, const int tag,
     gmsh::model::mesh::getBarycenters(elementType, tag, fast, primary, api_barycenters_, task, numTasks);
     vector2ptr(api_barycenters_, barycenters, barycenters_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1421,8 +1421,8 @@ GMSH_API void gmshModelMeshPreallocateBarycenters(const int elementType, double
     gmsh::model::mesh::preallocateBarycenters(elementType, api_barycenters_, tag);
     vector2ptr(api_barycenters_, barycenters, barycenters_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1434,8 +1434,8 @@ GMSH_API void gmshModelMeshGetElementEdgeNodes(const int elementType, size_t **
     gmsh::model::mesh::getElementEdgeNodes(elementType, api_nodeTags_, tag, primary, task, numTasks);
     vector2ptr(api_nodeTags_, nodeTags, nodeTags_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1447,8 +1447,8 @@ GMSH_API void gmshModelMeshGetElementFaceNodes(const int elementType, const int
     gmsh::model::mesh::getElementFaceNodes(elementType, faceType, api_nodeTags_, tag, primary, task, numTasks);
     vector2ptr(api_nodeTags_, nodeTags, nodeTags_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1462,8 +1462,8 @@ GMSH_API void gmshModelMeshGetGhostElements(const int dim, const int tag, size_t
     vector2ptr(api_elementTags_, elementTags, elementTags_n);
     vector2ptr(api_partitions_, partitions, partitions_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1478,8 +1478,8 @@ GMSH_API void gmshModelMeshSetSize(int * dimTags, size_t dimTags_n, const double
     }
     gmsh::model::mesh::setSize(api_dimTags_, size);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1491,8 +1491,8 @@ GMSH_API void gmshModelMeshSetSizeAtParametricPoints(const int dim, const int ta
     std::vector<double> api_sizes_(sizes, sizes + sizes_n);
     gmsh::model::mesh::setSizeAtParametricPoints(dim, tag, api_parametricCoord_, api_sizes_);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1502,8 +1502,8 @@ GMSH_API void gmshModelMeshSetTransfiniteCurve(const int tag, const int numNodes
   try {
     gmsh::model::mesh::setTransfiniteCurve(tag, numNodes, meshType, coef);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1514,8 +1514,8 @@ GMSH_API void gmshModelMeshSetTransfiniteSurface(const int tag, const char * arr
     std::vector<int> api_cornerTags_(cornerTags, cornerTags + cornerTags_n);
     gmsh::model::mesh::setTransfiniteSurface(tag, arrangement, api_cornerTags_);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1526,8 +1526,8 @@ GMSH_API void gmshModelMeshSetTransfiniteVolume(const int tag, int * cornerTags,
     std::vector<int> api_cornerTags_(cornerTags, cornerTags + cornerTags_n);
     gmsh::model::mesh::setTransfiniteVolume(tag, api_cornerTags_);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1537,8 +1537,8 @@ GMSH_API void gmshModelMeshSetRecombine(const int dim, const int tag, int * ierr
   try {
     gmsh::model::mesh::setRecombine(dim, tag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1548,8 +1548,8 @@ GMSH_API void gmshModelMeshSetSmoothing(const int dim, const int tag, const int
   try {
     gmsh::model::mesh::setSmoothing(dim, tag, val);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1559,8 +1559,8 @@ GMSH_API void gmshModelMeshSetReverse(const int dim, const int tag, const int va
   try {
     gmsh::model::mesh::setReverse(dim, tag, val);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1570,8 +1570,8 @@ GMSH_API void gmshModelMeshSetAlgorithm(const int dim, const int tag, const int
   try {
     gmsh::model::mesh::setAlgorithm(dim, tag, val);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1581,8 +1581,8 @@ GMSH_API void gmshModelMeshSetSizeFromBoundary(const int dim, const int tag, con
   try {
     gmsh::model::mesh::setSizeFromBoundary(dim, tag, val);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1593,8 +1593,8 @@ GMSH_API void gmshModelMeshSetCompound(const int dim, int * tags, size_t tags_n,
     std::vector<int> api_tags_(tags, tags + tags_n);
     gmsh::model::mesh::setCompound(dim, api_tags_);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1604,8 +1604,8 @@ GMSH_API void gmshModelMeshSetOutwardOrientation(const int tag, int * ierr)
   try {
     gmsh::model::mesh::setOutwardOrientation(tag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1616,8 +1616,8 @@ GMSH_API void gmshModelMeshEmbed(const int dim, int * tags, size_t tags_n, const
     std::vector<int> api_tags_(tags, tags + tags_n);
     gmsh::model::mesh::embed(dim, api_tags_, inDim, inTag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1632,8 +1632,8 @@ GMSH_API void gmshModelMeshRemoveEmbedded(int * dimTags, size_t dimTags_n, const
     }
     gmsh::model::mesh::removeEmbedded(api_dimTags_, dim);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1644,8 +1644,8 @@ GMSH_API void gmshModelMeshReorderElements(const int elementType, const int tag,
     std::vector<std::size_t> api_ordering_(ordering, ordering + ordering_n);
     gmsh::model::mesh::reorderElements(elementType, tag, api_ordering_);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1655,8 +1655,8 @@ GMSH_API void gmshModelMeshRenumberNodes(int * ierr)
   try {
     gmsh::model::mesh::renumberNodes();
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1666,8 +1666,8 @@ GMSH_API void gmshModelMeshRenumberElements(int * ierr)
   try {
     gmsh::model::mesh::renumberElements();
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1680,8 +1680,8 @@ GMSH_API void gmshModelMeshSetPeriodic(const int dim, int * tags, size_t tags_n,
     std::vector<double> api_affineTransform_(affineTransform, affineTransform + affineTransform_n);
     gmsh::model::mesh::setPeriodic(dim, api_tags_, api_tagsMaster_, api_affineTransform_);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1697,8 +1697,8 @@ GMSH_API void gmshModelMeshGetPeriodicNodes(const int dim, const int tag, int *
     vector2ptr(api_nodeTagsMaster_, nodeTagsMaster, nodeTagsMaster_n);
     vector2ptr(api_affineTransform_, affineTransform, affineTransform_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1708,8 +1708,8 @@ GMSH_API void gmshModelMeshRemoveDuplicateNodes(int * ierr)
   try {
     gmsh::model::mesh::removeDuplicateNodes();
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1719,8 +1719,8 @@ GMSH_API void gmshModelMeshSplitQuadrangles(const double quality, const int tag,
   try {
     gmsh::model::mesh::splitQuadrangles(quality, tag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1730,8 +1730,8 @@ GMSH_API void gmshModelMeshClassifySurfaces(const double angle, const int bounda
   try {
     gmsh::model::mesh::classifySurfaces(angle, boundary, forReparametrization, curveAngle);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1746,8 +1746,8 @@ GMSH_API void gmshModelMeshCreateGeometry(int * dimTags, size_t dimTags_n, int *
     }
     gmsh::model::mesh::createGeometry(api_dimTags_);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1757,8 +1757,8 @@ GMSH_API void gmshModelMeshCreateTopology(const int makeSimplyConnected, const i
   try {
     gmsh::model::mesh::createTopology(makeSimplyConnected, exportDiscrete);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1771,8 +1771,8 @@ GMSH_API void gmshModelMeshComputeHomology(int * domainTags, size_t domainTags_n
     std::vector<int> api_dims_(dims, dims + dims_n);
     gmsh::model::mesh::computeHomology(api_domainTags_, api_subdomainTags_, api_dims_);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1785,8 +1785,8 @@ GMSH_API void gmshModelMeshComputeCohomology(int * domainTags, size_t domainTags
     std::vector<int> api_dims_(dims, dims + dims_n);
     gmsh::model::mesh::computeCohomology(api_domainTags_, api_subdomainTags_, api_dims_);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1798,8 +1798,8 @@ GMSH_API void gmshModelMeshComputeCrossField(int ** viewTags, size_t * viewTags_
     gmsh::model::mesh::computeCrossField(api_viewTags_);
     vector2ptr(api_viewTags_, viewTags, viewTags_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1810,8 +1810,8 @@ GMSH_API int gmshModelMeshFieldAdd(const char * fieldType, const int tag, int *
   try {
     result_api_ = gmsh::model::mesh::field::add(fieldType, tag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -1822,8 +1822,8 @@ GMSH_API void gmshModelMeshFieldRemove(const int tag, int * ierr)
   try {
     gmsh::model::mesh::field::remove(tag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1833,8 +1833,8 @@ GMSH_API void gmshModelMeshFieldSetNumber(const int tag, const char * option, co
   try {
     gmsh::model::mesh::field::setNumber(tag, option, value);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1844,8 +1844,8 @@ GMSH_API void gmshModelMeshFieldSetString(const int tag, const char * option, co
   try {
     gmsh::model::mesh::field::setString(tag, option, value);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1856,8 +1856,8 @@ GMSH_API void gmshModelMeshFieldSetNumbers(const int tag, const char * option, d
     std::vector<double> api_value_(value, value + value_n);
     gmsh::model::mesh::field::setNumbers(tag, option, api_value_);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1867,8 +1867,8 @@ GMSH_API void gmshModelMeshFieldSetAsBackgroundMesh(const int tag, int * ierr)
   try {
     gmsh::model::mesh::field::setAsBackgroundMesh(tag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1878,8 +1878,8 @@ GMSH_API void gmshModelMeshFieldSetAsBoundaryLayer(const int tag, int * ierr)
   try {
     gmsh::model::mesh::field::setAsBoundaryLayer(tag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -1890,8 +1890,8 @@ GMSH_API int gmshModelGeoAddPoint(const double x, const double y, const double z
   try {
     result_api_ = gmsh::model::geo::addPoint(x, y, z, meshSize, tag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -1903,8 +1903,8 @@ GMSH_API int gmshModelGeoAddLine(const int startTag, const int endTag, const int
   try {
     result_api_ = gmsh::model::geo::addLine(startTag, endTag, tag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -1916,8 +1916,8 @@ GMSH_API int gmshModelGeoAddCircleArc(const int startTag, const int centerTag, c
   try {
     result_api_ = gmsh::model::geo::addCircleArc(startTag, centerTag, endTag, tag, nx, ny, nz);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -1929,8 +1929,8 @@ GMSH_API int gmshModelGeoAddEllipseArc(const int startTag, const int centerTag,
   try {
     result_api_ = gmsh::model::geo::addEllipseArc(startTag, centerTag, majorTag, endTag, tag, nx, ny, nz);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -1943,8 +1943,8 @@ GMSH_API int gmshModelGeoAddSpline(int * pointTags, size_t pointTags_n, const in
     std::vector<int> api_pointTags_(pointTags, pointTags + pointTags_n);
     result_api_ = gmsh::model::geo::addSpline(api_pointTags_, tag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -1957,8 +1957,8 @@ GMSH_API int gmshModelGeoAddBSpline(int * pointTags, size_t pointTags_n, const i
     std::vector<int> api_pointTags_(pointTags, pointTags + pointTags_n);
     result_api_ = gmsh::model::geo::addBSpline(api_pointTags_, tag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -1971,8 +1971,8 @@ GMSH_API int gmshModelGeoAddBezier(int * pointTags, size_t pointTags_n, const in
     std::vector<int> api_pointTags_(pointTags, pointTags + pointTags_n);
     result_api_ = gmsh::model::geo::addBezier(api_pointTags_, tag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -1985,8 +1985,8 @@ GMSH_API int gmshModelGeoAddPolyline(int * pointTags, size_t pointTags_n, const
     std::vector<int> api_pointTags_(pointTags, pointTags + pointTags_n);
     result_api_ = gmsh::model::geo::addPolyline(api_pointTags_, tag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -1999,8 +1999,8 @@ GMSH_API int gmshModelGeoAddCompoundSpline(int * curveTags, size_t curveTags_n,
     std::vector<int> api_curveTags_(curveTags, curveTags + curveTags_n);
     result_api_ = gmsh::model::geo::addCompoundSpline(api_curveTags_, numIntervals, tag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -2013,8 +2013,8 @@ GMSH_API int gmshModelGeoAddCompoundBSpline(int * curveTags, size_t curveTags_n,
     std::vector<int> api_curveTags_(curveTags, curveTags + curveTags_n);
     result_api_ = gmsh::model::geo::addCompoundBSpline(api_curveTags_, numIntervals, tag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -2027,8 +2027,8 @@ GMSH_API int gmshModelGeoAddCurveLoop(int * curveTags, size_t curveTags_n, const
     std::vector<int> api_curveTags_(curveTags, curveTags + curveTags_n);
     result_api_ = gmsh::model::geo::addCurveLoop(api_curveTags_, tag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -2041,8 +2041,8 @@ GMSH_API int gmshModelGeoAddPlaneSurface(int * wireTags, size_t wireTags_n, cons
     std::vector<int> api_wireTags_(wireTags, wireTags + wireTags_n);
     result_api_ = gmsh::model::geo::addPlaneSurface(api_wireTags_, tag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -2055,8 +2055,8 @@ GMSH_API int gmshModelGeoAddSurfaceFilling(int * wireTags, size_t wireTags_n, co
     std::vector<int> api_wireTags_(wireTags, wireTags + wireTags_n);
     result_api_ = gmsh::model::geo::addSurfaceFilling(api_wireTags_, tag, sphereCenterTag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -2069,8 +2069,8 @@ GMSH_API int gmshModelGeoAddSurfaceLoop(int * surfaceTags, size_t surfaceTags_n,
     std::vector<int> api_surfaceTags_(surfaceTags, surfaceTags + surfaceTags_n);
     result_api_ = gmsh::model::geo::addSurfaceLoop(api_surfaceTags_, tag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -2083,8 +2083,8 @@ GMSH_API int gmshModelGeoAddVolume(int * shellTags, size_t shellTags_n, const in
     std::vector<int> api_shellTags_(shellTags, shellTags + shellTags_n);
     result_api_ = gmsh::model::geo::addVolume(api_shellTags_, tag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -2104,8 +2104,8 @@ GMSH_API void gmshModelGeoExtrude(int * dimTags, size_t dimTags_n, const double
     gmsh::model::geo::extrude(api_dimTags_, dx, dy, dz, api_outDimTags_, api_numElements_, api_heights_, recombine);
     vectorpair2intptr(api_outDimTags_, outDimTags, outDimTags_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -2124,8 +2124,8 @@ GMSH_API void gmshModelGeoRevolve(int * dimTags, size_t dimTags_n, const double
     gmsh::model::geo::revolve(api_dimTags_, x, y, z, ax, ay, az, angle, api_outDimTags_, api_numElements_, api_heights_, recombine);
     vectorpair2intptr(api_outDimTags_, outDimTags, outDimTags_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -2144,8 +2144,8 @@ GMSH_API void gmshModelGeoTwist(int * dimTags, size_t dimTags_n, const double x,
     gmsh::model::geo::twist(api_dimTags_, x, y, z, dx, dy, dz, ax, ay, az, angle, api_outDimTags_, api_numElements_, api_heights_, recombine);
     vectorpair2intptr(api_outDimTags_, outDimTags, outDimTags_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -2160,8 +2160,8 @@ GMSH_API void gmshModelGeoTranslate(int * dimTags, size_t dimTags_n, const doubl
     }
     gmsh::model::geo::translate(api_dimTags_, dx, dy, dz);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -2176,8 +2176,8 @@ GMSH_API void gmshModelGeoRotate(int * dimTags, size_t dimTags_n, const double x
     }
     gmsh::model::geo::rotate(api_dimTags_, x, y, z, ax, ay, az, angle);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -2192,8 +2192,8 @@ GMSH_API void gmshModelGeoDilate(int * dimTags, size_t dimTags_n, const double x
     }
     gmsh::model::geo::dilate(api_dimTags_, x, y, z, a, b, c);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -2208,8 +2208,8 @@ GMSH_API void gmshModelGeoMirror(int * dimTags, size_t dimTags_n, const double a
     }
     gmsh::model::geo::mirror(api_dimTags_, a, b, c, d);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -2224,8 +2224,8 @@ GMSH_API void gmshModelGeoSymmetrize(int * dimTags, size_t dimTags_n, const doub
     }
     gmsh::model::geo::symmetrize(api_dimTags_, a, b, c, d);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -2242,8 +2242,8 @@ GMSH_API void gmshModelGeoCopy(int * dimTags, size_t dimTags_n, int ** outDimTag
     gmsh::model::geo::copy(api_dimTags_, api_outDimTags_);
     vectorpair2intptr(api_outDimTags_, outDimTags, outDimTags_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -2258,8 +2258,8 @@ GMSH_API void gmshModelGeoRemove(int * dimTags, size_t dimTags_n, const int recu
     }
     gmsh::model::geo::remove(api_dimTags_, recursive);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -2269,8 +2269,8 @@ GMSH_API void gmshModelGeoRemoveAllDuplicates(int * ierr)
   try {
     gmsh::model::geo::removeAllDuplicates();
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -2283,8 +2283,8 @@ GMSH_API void gmshModelGeoSplitCurve(const int tag, int * pointTags, size_t poin
     gmsh::model::geo::splitCurve(tag, api_pointTags_, api_curveTags_);
     vector2ptr(api_curveTags_, curveTags, curveTags_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -2295,8 +2295,8 @@ GMSH_API int gmshModelGeoGetMaxTag(const int dim, int * ierr)
   try {
     result_api_ = gmsh::model::geo::getMaxTag(dim);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -2307,8 +2307,8 @@ GMSH_API void gmshModelGeoSetMaxTag(const int dim, const int maxTag, int * ierr)
   try {
     gmsh::model::geo::setMaxTag(dim, maxTag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -2318,8 +2318,8 @@ GMSH_API void gmshModelGeoSynchronize(int * ierr)
   try {
     gmsh::model::geo::synchronize();
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -2334,8 +2334,8 @@ GMSH_API void gmshModelGeoMeshSetSize(int * dimTags, size_t dimTags_n, const dou
     }
     gmsh::model::geo::mesh::setSize(api_dimTags_, size);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -2345,8 +2345,8 @@ GMSH_API void gmshModelGeoMeshSetTransfiniteCurve(const int tag, const int nPoin
   try {
     gmsh::model::geo::mesh::setTransfiniteCurve(tag, nPoints, meshType, coef);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -2357,8 +2357,8 @@ GMSH_API void gmshModelGeoMeshSetTransfiniteSurface(const int tag, const char *
     std::vector<int> api_cornerTags_(cornerTags, cornerTags + cornerTags_n);
     gmsh::model::geo::mesh::setTransfiniteSurface(tag, arrangement, api_cornerTags_);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -2369,8 +2369,8 @@ GMSH_API void gmshModelGeoMeshSetTransfiniteVolume(const int tag, int * cornerTa
     std::vector<int> api_cornerTags_(cornerTags, cornerTags + cornerTags_n);
     gmsh::model::geo::mesh::setTransfiniteVolume(tag, api_cornerTags_);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -2380,8 +2380,8 @@ GMSH_API void gmshModelGeoMeshSetRecombine(const int dim, const int tag, const d
   try {
     gmsh::model::geo::mesh::setRecombine(dim, tag, angle);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -2391,8 +2391,8 @@ GMSH_API void gmshModelGeoMeshSetSmoothing(const int dim, const int tag, const i
   try {
     gmsh::model::geo::mesh::setSmoothing(dim, tag, val);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -2402,8 +2402,8 @@ GMSH_API void gmshModelGeoMeshSetReverse(const int dim, const int tag, const int
   try {
     gmsh::model::geo::mesh::setReverse(dim, tag, val);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -2413,8 +2413,8 @@ GMSH_API void gmshModelGeoMeshSetAlgorithm(const int dim, const int tag, const i
   try {
     gmsh::model::geo::mesh::setAlgorithm(dim, tag, val);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -2424,8 +2424,8 @@ GMSH_API void gmshModelGeoMeshSetSizeFromBoundary(const int dim, const int tag,
   try {
     gmsh::model::geo::mesh::setSizeFromBoundary(dim, tag, val);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -2436,8 +2436,8 @@ GMSH_API int gmshModelOccAddPoint(const double x, const double y, const double z
   try {
     result_api_ = gmsh::model::occ::addPoint(x, y, z, meshSize, tag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -2449,8 +2449,8 @@ GMSH_API int gmshModelOccAddLine(const int startTag, const int endTag, const int
   try {
     result_api_ = gmsh::model::occ::addLine(startTag, endTag, tag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -2462,8 +2462,8 @@ GMSH_API int gmshModelOccAddCircleArc(const int startTag, const int centerTag, c
   try {
     result_api_ = gmsh::model::occ::addCircleArc(startTag, centerTag, endTag, tag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -2475,8 +2475,8 @@ GMSH_API int gmshModelOccAddCircle(const double x, const double y, const double
   try {
     result_api_ = gmsh::model::occ::addCircle(x, y, z, r, tag, angle1, angle2);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -2488,8 +2488,8 @@ GMSH_API int gmshModelOccAddEllipseArc(const int startTag, const int centerTag,
   try {
     result_api_ = gmsh::model::occ::addEllipseArc(startTag, centerTag, majorTag, endTag, tag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -2501,8 +2501,8 @@ GMSH_API int gmshModelOccAddEllipse(const double x, const double y, const double
   try {
     result_api_ = gmsh::model::occ::addEllipse(x, y, z, r1, r2, tag, angle1, angle2);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -2515,8 +2515,8 @@ GMSH_API int gmshModelOccAddSpline(int * pointTags, size_t pointTags_n, const in
     std::vector<int> api_pointTags_(pointTags, pointTags + pointTags_n);
     result_api_ = gmsh::model::occ::addSpline(api_pointTags_, tag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -2532,8 +2532,8 @@ GMSH_API int gmshModelOccAddBSpline(int * pointTags, size_t pointTags_n, const i
     std::vector<int> api_multiplicities_(multiplicities, multiplicities + multiplicities_n);
     result_api_ = gmsh::model::occ::addBSpline(api_pointTags_, tag, degree, api_weights_, api_knots_, api_multiplicities_);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -2546,8 +2546,8 @@ GMSH_API int gmshModelOccAddBezier(int * pointTags, size_t pointTags_n, const in
     std::vector<int> api_pointTags_(pointTags, pointTags + pointTags_n);
     result_api_ = gmsh::model::occ::addBezier(api_pointTags_, tag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -2560,8 +2560,8 @@ GMSH_API int gmshModelOccAddWire(int * curveTags, size_t curveTags_n, const int
     std::vector<int> api_curveTags_(curveTags, curveTags + curveTags_n);
     result_api_ = gmsh::model::occ::addWire(api_curveTags_, tag, checkClosed);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -2574,8 +2574,8 @@ GMSH_API int gmshModelOccAddCurveLoop(int * curveTags, size_t curveTags_n, const
     std::vector<int> api_curveTags_(curveTags, curveTags + curveTags_n);
     result_api_ = gmsh::model::occ::addCurveLoop(api_curveTags_, tag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -2587,8 +2587,8 @@ GMSH_API int gmshModelOccAddRectangle(const double x, const double y, const doub
   try {
     result_api_ = gmsh::model::occ::addRectangle(x, y, z, dx, dy, tag, roundedRadius);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -2600,8 +2600,8 @@ GMSH_API int gmshModelOccAddDisk(const double xc, const double yc, const double
   try {
     result_api_ = gmsh::model::occ::addDisk(xc, yc, zc, rx, ry, tag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -2614,8 +2614,8 @@ GMSH_API int gmshModelOccAddPlaneSurface(int * wireTags, size_t wireTags_n, cons
     std::vector<int> api_wireTags_(wireTags, wireTags + wireTags_n);
     result_api_ = gmsh::model::occ::addPlaneSurface(api_wireTags_, tag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -2628,8 +2628,8 @@ GMSH_API int gmshModelOccAddSurfaceFilling(const int wireTag, const int tag, int
     std::vector<int> api_pointTags_(pointTags, pointTags + pointTags_n);
     result_api_ = gmsh::model::occ::addSurfaceFilling(wireTag, tag, api_pointTags_);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -2641,8 +2641,8 @@ GMSH_API int gmshModelOccAddBSplineFilling(const int wireTag, const int tag, con
   try {
     result_api_ = gmsh::model::occ::addBSplineFilling(wireTag, tag, type);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -2654,8 +2654,8 @@ GMSH_API int gmshModelOccAddBezierFilling(const int wireTag, const int tag, cons
   try {
     result_api_ = gmsh::model::occ::addBezierFilling(wireTag, tag, type);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -2673,8 +2673,8 @@ GMSH_API int gmshModelOccAddBSplineSurface(int * pointTags, size_t pointTags_n,
     std::vector<int> api_multiplicitiesV_(multiplicitiesV, multiplicitiesV + multiplicitiesV_n);
     result_api_ = gmsh::model::occ::addBSplineSurface(api_pointTags_, numPointsU, tag, degreeU, degreeV, api_weights_, api_knotsU_, api_knotsV_, api_multiplicitiesU_, api_multiplicitiesV_);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -2687,8 +2687,8 @@ GMSH_API int gmshModelOccAddBezierSurface(int * pointTags, size_t pointTags_n, c
     std::vector<int> api_pointTags_(pointTags, pointTags + pointTags_n);
     result_api_ = gmsh::model::occ::addBezierSurface(api_pointTags_, numPointsU, tag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -2701,8 +2701,8 @@ GMSH_API int gmshModelOccAddSurfaceLoop(int * surfaceTags, size_t surfaceTags_n,
     std::vector<int> api_surfaceTags_(surfaceTags, surfaceTags + surfaceTags_n);
     result_api_ = gmsh::model::occ::addSurfaceLoop(api_surfaceTags_, tag, sewing);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -2715,8 +2715,8 @@ GMSH_API int gmshModelOccAddVolume(int * shellTags, size_t shellTags_n, const in
     std::vector<int> api_shellTags_(shellTags, shellTags + shellTags_n);
     result_api_ = gmsh::model::occ::addVolume(api_shellTags_, tag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -2728,8 +2728,8 @@ GMSH_API int gmshModelOccAddSphere(const double xc, const double yc, const doubl
   try {
     result_api_ = gmsh::model::occ::addSphere(xc, yc, zc, radius, tag, angle1, angle2, angle3);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -2741,8 +2741,8 @@ GMSH_API int gmshModelOccAddBox(const double x, const double y, const double z,
   try {
     result_api_ = gmsh::model::occ::addBox(x, y, z, dx, dy, dz, tag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -2754,8 +2754,8 @@ GMSH_API int gmshModelOccAddCylinder(const double x, const double y, const doubl
   try {
     result_api_ = gmsh::model::occ::addCylinder(x, y, z, dx, dy, dz, r, tag, angle);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -2767,8 +2767,8 @@ GMSH_API int gmshModelOccAddCone(const double x, const double y, const double z,
   try {
     result_api_ = gmsh::model::occ::addCone(x, y, z, dx, dy, dz, r1, r2, tag, angle);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -2780,8 +2780,8 @@ GMSH_API int gmshModelOccAddWedge(const double x, const double y, const double z
   try {
     result_api_ = gmsh::model::occ::addWedge(x, y, z, dx, dy, dz, tag, ltx);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -2793,8 +2793,8 @@ GMSH_API int gmshModelOccAddTorus(const double x, const double y, const double z
   try {
     result_api_ = gmsh::model::occ::addTorus(x, y, z, r1, r2, tag, angle);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -2808,8 +2808,8 @@ GMSH_API void gmshModelOccAddThruSections(int * wireTags, size_t wireTags_n, int
     gmsh::model::occ::addThruSections(api_wireTags_, api_outDimTags_, tag, makeSolid, makeRuled, maxDegree);
     vectorpair2intptr(api_outDimTags_, outDimTags, outDimTags_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -2822,8 +2822,8 @@ GMSH_API void gmshModelOccAddThickSolid(const int volumeTag, int * excludeSurfac
     gmsh::model::occ::addThickSolid(volumeTag, api_excludeSurfaceTags_, offset, api_outDimTags_, tag);
     vectorpair2intptr(api_outDimTags_, outDimTags, outDimTags_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -2842,8 +2842,8 @@ GMSH_API void gmshModelOccExtrude(int * dimTags, size_t dimTags_n, const double
     gmsh::model::occ::extrude(api_dimTags_, dx, dy, dz, api_outDimTags_, api_numElements_, api_heights_, recombine);
     vectorpair2intptr(api_outDimTags_, outDimTags, outDimTags_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -2862,8 +2862,8 @@ GMSH_API void gmshModelOccRevolve(int * dimTags, size_t dimTags_n, const double
     gmsh::model::occ::revolve(api_dimTags_, x, y, z, ax, ay, az, angle, api_outDimTags_, api_numElements_, api_heights_, recombine);
     vectorpair2intptr(api_outDimTags_, outDimTags, outDimTags_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -2880,8 +2880,8 @@ GMSH_API void gmshModelOccAddPipe(int * dimTags, size_t dimTags_n, const int wir
     gmsh::model::occ::addPipe(api_dimTags_, wireTag, api_outDimTags_);
     vectorpair2intptr(api_outDimTags_, outDimTags, outDimTags_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -2896,8 +2896,8 @@ GMSH_API void gmshModelOccFillet(int * volumeTags, size_t volumeTags_n, int * cu
     gmsh::model::occ::fillet(api_volumeTags_, api_curveTags_, api_radii_, api_outDimTags_, removeVolume);
     vectorpair2intptr(api_outDimTags_, outDimTags, outDimTags_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -2913,8 +2913,8 @@ GMSH_API void gmshModelOccChamfer(int * volumeTags, size_t volumeTags_n, int * c
     gmsh::model::occ::chamfer(api_volumeTags_, api_curveTags_, api_surfaceTags_, api_distances_, api_outDimTags_, removeVolume);
     vectorpair2intptr(api_outDimTags_, outDimTags, outDimTags_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -2938,8 +2938,8 @@ GMSH_API void gmshModelOccFuse(int * objectDimTags, size_t objectDimTags_n, int
     vectorpair2intptr(api_outDimTags_, outDimTags, outDimTags_n);
     vectorvectorpair2intptrptr(api_outDimTagsMap_, outDimTagsMap, outDimTagsMap_n, outDimTagsMap_nn);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -2963,8 +2963,8 @@ GMSH_API void gmshModelOccIntersect(int * objectDimTags, size_t objectDimTags_n,
     vectorpair2intptr(api_outDimTags_, outDimTags, outDimTags_n);
     vectorvectorpair2intptrptr(api_outDimTagsMap_, outDimTagsMap, outDimTagsMap_n, outDimTagsMap_nn);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -2988,8 +2988,8 @@ GMSH_API void gmshModelOccCut(int * objectDimTags, size_t objectDimTags_n, int *
     vectorpair2intptr(api_outDimTags_, outDimTags, outDimTags_n);
     vectorvectorpair2intptrptr(api_outDimTagsMap_, outDimTagsMap, outDimTagsMap_n, outDimTagsMap_nn);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3013,8 +3013,8 @@ GMSH_API void gmshModelOccFragment(int * objectDimTags, size_t objectDimTags_n,
     vectorpair2intptr(api_outDimTags_, outDimTags, outDimTags_n);
     vectorvectorpair2intptrptr(api_outDimTagsMap_, outDimTagsMap, outDimTagsMap_n, outDimTagsMap_nn);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3029,8 +3029,8 @@ GMSH_API void gmshModelOccTranslate(int * dimTags, size_t dimTags_n, const doubl
     }
     gmsh::model::occ::translate(api_dimTags_, dx, dy, dz);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3045,8 +3045,8 @@ GMSH_API void gmshModelOccRotate(int * dimTags, size_t dimTags_n, const double x
     }
     gmsh::model::occ::rotate(api_dimTags_, x, y, z, ax, ay, az, angle);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3061,8 +3061,8 @@ GMSH_API void gmshModelOccDilate(int * dimTags, size_t dimTags_n, const double x
     }
     gmsh::model::occ::dilate(api_dimTags_, x, y, z, a, b, c);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3077,8 +3077,8 @@ GMSH_API void gmshModelOccMirror(int * dimTags, size_t dimTags_n, const double a
     }
     gmsh::model::occ::mirror(api_dimTags_, a, b, c, d);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3093,8 +3093,8 @@ GMSH_API void gmshModelOccSymmetrize(int * dimTags, size_t dimTags_n, const doub
     }
     gmsh::model::occ::symmetrize(api_dimTags_, a, b, c, d);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3110,8 +3110,8 @@ GMSH_API void gmshModelOccAffineTransform(int * dimTags, size_t dimTags_n, doubl
     std::vector<double> api_a_(a, a + a_n);
     gmsh::model::occ::affineTransform(api_dimTags_, api_a_);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3128,8 +3128,8 @@ GMSH_API void gmshModelOccCopy(int * dimTags, size_t dimTags_n, int ** outDimTag
     gmsh::model::occ::copy(api_dimTags_, api_outDimTags_);
     vectorpair2intptr(api_outDimTags_, outDimTags, outDimTags_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3144,8 +3144,8 @@ GMSH_API void gmshModelOccRemove(int * dimTags, size_t dimTags_n, const int recu
     }
     gmsh::model::occ::remove(api_dimTags_, recursive);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3155,8 +3155,8 @@ GMSH_API void gmshModelOccRemoveAllDuplicates(int * ierr)
   try {
     gmsh::model::occ::removeAllDuplicates();
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3173,8 +3173,8 @@ GMSH_API void gmshModelOccHealShapes(int ** outDimTags, size_t * outDimTags_n, i
     gmsh::model::occ::healShapes(api_outDimTags_, api_dimTags_, tolerance, fixDegenerated, fixSmallEdges, fixSmallFaces, sewFaces, makeSolids);
     vectorpair2intptr(api_outDimTags_, outDimTags, outDimTags_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3186,8 +3186,8 @@ GMSH_API void gmshModelOccImportShapes(const char * fileName, int ** outDimTags,
     gmsh::model::occ::importShapes(fileName, api_outDimTags_, highestDimOnly, format);
     vectorpair2intptr(api_outDimTags_, outDimTags, outDimTags_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3199,8 +3199,8 @@ GMSH_API void gmshModelOccImportShapesNativePointer(const void * shape, int ** o
     gmsh::model::occ::importShapesNativePointer(shape, api_outDimTags_, highestDimOnly);
     vectorpair2intptr(api_outDimTags_, outDimTags, outDimTags_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3212,8 +3212,8 @@ GMSH_API void gmshModelOccGetEntities(int ** dimTags, size_t * dimTags_n, const
     gmsh::model::occ::getEntities(api_dimTags_, dim);
     vectorpair2intptr(api_dimTags_, dimTags, dimTags_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3225,8 +3225,8 @@ GMSH_API void gmshModelOccGetEntitiesInBoundingBox(const double xmin, const doub
     gmsh::model::occ::getEntitiesInBoundingBox(xmin, ymin, zmin, xmax, ymax, zmax, api_tags_, dim);
     vectorpair2intptr(api_tags_, tags, tags_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3236,8 +3236,8 @@ GMSH_API void gmshModelOccGetBoundingBox(const int dim, const int tag, double *
   try {
     gmsh::model::occ::getBoundingBox(dim, tag, *xmin, *ymin, *zmin, *xmax, *ymax, *zmax);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3247,8 +3247,8 @@ GMSH_API void gmshModelOccGetMass(const int dim, const int tag, double * mass, i
   try {
     gmsh::model::occ::getMass(dim, tag, *mass);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3258,8 +3258,8 @@ GMSH_API void gmshModelOccGetCenterOfMass(const int dim, const int tag, double *
   try {
     gmsh::model::occ::getCenterOfMass(dim, tag, *x, *y, *z);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3271,8 +3271,8 @@ GMSH_API void gmshModelOccGetMatrixOfInertia(const int dim, const int tag, doubl
     gmsh::model::occ::getMatrixOfInertia(dim, tag, api_mat_);
     vector2ptr(api_mat_, mat, mat_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3283,8 +3283,8 @@ GMSH_API int gmshModelOccGetMaxTag(const int dim, int * ierr)
   try {
     result_api_ = gmsh::model::occ::getMaxTag(dim);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -3295,8 +3295,8 @@ GMSH_API void gmshModelOccSetMaxTag(const int dim, const int maxTag, int * ierr)
   try {
     gmsh::model::occ::setMaxTag(dim, maxTag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3306,8 +3306,8 @@ GMSH_API void gmshModelOccSynchronize(int * ierr)
   try {
     gmsh::model::occ::synchronize();
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3322,8 +3322,8 @@ GMSH_API void gmshModelOccMeshSetSize(int * dimTags, size_t dimTags_n, const dou
     }
     gmsh::model::occ::mesh::setSize(api_dimTags_, size);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3334,8 +3334,8 @@ GMSH_API int gmshViewAdd(const char * name, const int tag, int * ierr)
   try {
     result_api_ = gmsh::view::add(name, tag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -3346,8 +3346,8 @@ GMSH_API void gmshViewRemove(const int tag, int * ierr)
   try {
     gmsh::view::remove(tag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3358,8 +3358,8 @@ GMSH_API int gmshViewGetIndex(const int tag, int * ierr)
   try {
     result_api_ = gmsh::view::getIndex(tag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -3372,8 +3372,8 @@ GMSH_API void gmshViewGetTags(int ** tags, size_t * tags_n, int * ierr)
     gmsh::view::getTags(api_tags_);
     vector2ptr(api_tags_, tags, tags_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3387,8 +3387,8 @@ GMSH_API void gmshViewAddModelData(const int tag, const int step, const char * m
       api_data_[i] = std::vector<double>(data[i], data[i] + data_n[i]);
     gmsh::view::addModelData(tag, step, modelName, dataType, api_tags_, api_data_, time, numComponents, partition);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3400,8 +3400,8 @@ GMSH_API void gmshViewAddHomogeneousModelData(const int tag, const int step, con
     std::vector<double> api_data_(data, data + data_n);
     gmsh::view::addHomogeneousModelData(tag, step, modelName, dataType, api_tags_, api_data_, time, numComponents, partition);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3417,8 +3417,8 @@ GMSH_API void gmshViewGetHomogeneousModelData(const int tag, const int step, cha
     vector2ptr(api_tags_, tags, tags_n);
     vector2ptr(api_data_, data, data_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3429,8 +3429,8 @@ GMSH_API void gmshViewAddListData(const int tag, const char * dataType, const in
     std::vector<double> api_data_(data, data + data_n);
     gmsh::view::addListData(tag, dataType, numEle, api_data_);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3446,8 +3446,8 @@ GMSH_API void gmshViewGetListData(const int tag, char *** dataType, size_t * dat
     vector2ptr(api_numElements_, numElements, numElements_n);
     vectorvector2ptrptr(api_data_, data, data_n, data_nn);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3460,8 +3460,8 @@ GMSH_API void gmshViewAddListDataString(const int tag, double * coord, size_t co
     std::vector<std::string> api_style_(style, style + style_n);
     gmsh::view::addListDataString(tag, api_coord_, api_data_, api_style_);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3477,8 +3477,8 @@ GMSH_API void gmshViewGetListDataStrings(const int tag, const int dim, double **
     vectorstring2charptrptr(api_data_, data, data_n);
     vectorstring2charptrptr(api_style_, style, style_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3489,8 +3489,8 @@ GMSH_API int gmshViewAddAlias(const int refTag, const int copyOptions, const int
   try {
     result_api_ = gmsh::view::addAlias(refTag, copyOptions, tag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -3501,8 +3501,8 @@ GMSH_API void gmshViewCopyOptions(const int refTag, const int tag, int * ierr)
   try {
     gmsh::view::copyOptions(refTag, tag);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3512,8 +3512,8 @@ GMSH_API void gmshViewCombine(const char * what, const char * how, const int rem
   try {
     gmsh::view::combine(what, how, remove, copyOptions);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3528,8 +3528,8 @@ GMSH_API void gmshViewProbe(const int tag, const double x, const double y, const
     gmsh::view::probe(tag, x, y, z, api_value_, step, numComp, gradient, tolerance, api_xElemCoord_, api_yElemCoord_, api_zElemCoord_);
     vector2ptr(api_value_, value, value_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3539,8 +3539,8 @@ GMSH_API void gmshViewWrite(const int tag, const char * fileName, const int appe
   try {
     gmsh::view::write(tag, fileName, append);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3550,8 +3550,8 @@ GMSH_API void gmshPluginSetNumber(const char * name, const char * option, const
   try {
     gmsh::plugin::setNumber(name, option, value);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3561,8 +3561,8 @@ GMSH_API void gmshPluginSetString(const char * name, const char * option, const
   try {
     gmsh::plugin::setString(name, option, value);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3572,8 +3572,8 @@ GMSH_API void gmshPluginRun(const char * name, int * ierr)
   try {
     gmsh::plugin::run(name);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3583,8 +3583,8 @@ GMSH_API void gmshGraphicsDraw(int * ierr)
   try {
     gmsh::graphics::draw();
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3594,8 +3594,8 @@ GMSH_API void gmshFltkInitialize(int * ierr)
   try {
     gmsh::fltk::initialize();
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3605,8 +3605,8 @@ GMSH_API void gmshFltkWait(const double time, int * ierr)
   try {
     gmsh::fltk::wait(time);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3616,8 +3616,8 @@ GMSH_API void gmshFltkUpdate(int * ierr)
   try {
     gmsh::fltk::update();
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3627,8 +3627,8 @@ GMSH_API void gmshFltkAwake(const char * action, int * ierr)
   try {
     gmsh::fltk::awake(action);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3638,8 +3638,8 @@ GMSH_API void gmshFltkLock(int * ierr)
   try {
     gmsh::fltk::lock();
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3649,8 +3649,8 @@ GMSH_API void gmshFltkUnlock(int * ierr)
   try {
     gmsh::fltk::unlock();
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3660,8 +3660,8 @@ GMSH_API void gmshFltkRun(int * ierr)
   try {
     gmsh::fltk::run();
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3672,8 +3672,8 @@ GMSH_API int gmshFltkIsAvailable(int * ierr)
   try {
     result_api_ = gmsh::fltk::isAvailable();
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -3687,8 +3687,8 @@ GMSH_API int gmshFltkSelectEntities(int ** dimTags, size_t * dimTags_n, const in
     result_api_ = gmsh::fltk::selectEntities(api_dimTags_, dim);
     vectorpair2intptr(api_dimTags_, dimTags, dimTags_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -3702,8 +3702,8 @@ GMSH_API int gmshFltkSelectElements(size_t ** elementTags, size_t * elementTags_
     result_api_ = gmsh::fltk::selectElements(api_elementTags_);
     vector2ptr(api_elementTags_, elementTags, elementTags_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -3717,8 +3717,8 @@ GMSH_API int gmshFltkSelectViews(int ** viewTags, size_t * viewTags_n, int * ier
     result_api_ = gmsh::fltk::selectViews(api_viewTags_);
     vector2ptr(api_viewTags_, viewTags, viewTags_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -3729,8 +3729,8 @@ GMSH_API void gmshOnelabSet(const char * data, const char * format, int * ierr)
   try {
     gmsh::onelab::set(data, format);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3742,8 +3742,8 @@ GMSH_API void gmshOnelabGet(char ** data, const char * name, const char * format
     gmsh::onelab::get(api_data_, name, format);
     *data = strdup(api_data_.c_str());
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3754,8 +3754,8 @@ GMSH_API void gmshOnelabSetNumber(const char * name, double * value, size_t valu
     std::vector<double> api_value_(value, value + value_n);
     gmsh::onelab::setNumber(name, api_value_);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3766,8 +3766,8 @@ GMSH_API void gmshOnelabSetString(const char * name, char ** value, size_t value
     std::vector<std::string> api_value_(value, value + value_n);
     gmsh::onelab::setString(name, api_value_);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3779,8 +3779,8 @@ GMSH_API void gmshOnelabGetNumber(const char * name, double ** value, size_t * v
     gmsh::onelab::getNumber(name, api_value_);
     vector2ptr(api_value_, value, value_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3792,8 +3792,8 @@ GMSH_API void gmshOnelabGetString(const char * name, char *** value, size_t * va
     gmsh::onelab::getString(name, api_value_);
     vectorstring2charptrptr(api_value_, value, value_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3803,8 +3803,8 @@ GMSH_API void gmshOnelabClear(const char * name, int * ierr)
   try {
     gmsh::onelab::clear(name);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3814,8 +3814,8 @@ GMSH_API void gmshOnelabRun(const char * name, const char * command, int * ierr)
   try {
     gmsh::onelab::run(name, command);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3825,8 +3825,8 @@ GMSH_API void gmshLoggerWrite(const char * message, const char * level, int * ie
   try {
     gmsh::logger::write(message, level);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3836,8 +3836,8 @@ GMSH_API void gmshLoggerStart(int * ierr)
   try {
     gmsh::logger::start();
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3849,8 +3849,8 @@ GMSH_API void gmshLoggerGet(char *** log, size_t * log_n, int * ierr)
     gmsh::logger::get(api_log_);
     vectorstring2charptrptr(api_log_, log, log_n);
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3860,8 +3860,8 @@ GMSH_API void gmshLoggerStop(int * ierr)
   try {
     gmsh::logger::stop();
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
 }
 
@@ -3872,8 +3872,8 @@ GMSH_API double gmshLoggerGetWallTime(int * ierr)
   try {
     result_api_ = gmsh::logger::getWallTime();
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
@@ -3885,9 +3885,22 @@ GMSH_API double gmshLoggerGetCpuTime(int * ierr)
   try {
     result_api_ = gmsh::logger::getCpuTime();
   }
-  catch(int api_ierr_){
-    if(ierr) *ierr = api_ierr_;
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
   }
   return result_api_;
 }
 
+GMSH_API void gmshLoggerGetLastError(char ** error, int * ierr)
+{
+  if(ierr) *ierr = 0;
+  try {
+    std::string api_error_;
+    gmsh::logger::getLastError(api_error_);
+    *error = strdup(api_error_.c_str());
+  }
+  catch(const std::string &api_error_){
+    if(ierr) *ierr = 1;
+  }
+}
+
diff --git a/api/gmshc.h b/api/gmshc.h
index 079adcd834..9e7a395e4f 100644
--- a/api/gmshc.h
+++ b/api/gmshc.h
@@ -2633,4 +2633,8 @@ GMSH_API double gmshLoggerGetWallTime(int * ierr);
 /* Return CPU time. */
 GMSH_API double gmshLoggerGetCpuTime(int * ierr);
 
+/* Return last error message, if any. */
+GMSH_API void gmshLoggerGetLastError(char ** error,
+                                     int * ierr);
+
 #endif
diff --git a/doc/texinfo/api.texi b/doc/texinfo/api.texi
index 5b666801f9..5bf25a23f7 100644
--- a/doc/texinfo/api.texi
+++ b/doc/texinfo/api.texi
@@ -4649,5 +4649,17 @@ Return CPU time.
 floating point value
 @end table
 
+@item gmsh/logger/getLastError
+Return last error message, if any.
+
+@table @asis
+@item Input:
+-
+@item Output:
+@code{error}
+@item Return:
+-
+@end table
+
 @end ftable
 
-- 
GitLab