chiark / gitweb /
improve C++ header exceptions, rename NLOPT_FORCE_STOP to NLOPT_FORCED_STOP
[nlopt.git] / api / nlopt-in.hpp
index a18854443ac6c369c3887578e2761fa13581f59f..977d5aa6eaa94ab0d0af27662bce42f1d38e8ecf 100644 (file)
@@ -56,6 +56,19 @@ namespace nlopt {
   // (Note: it is inefficient to use std::vector<double> for the arguments,
   //  since that would require a copy to be made of NLopt's double* data.)
 
+  //////////////////////////////////////////////////////////////////////
+  
+  // NLopt-specific exceptions (corresponding to error codes):
+  class roundoff_limited : public std::runtime_error {
+  public:
+    roundoff_limited() : std::runtime_error("nlopt roundoff-limited") {}
+  };
+
+  class forced_stop : public std::runtime_error {
+  public:
+    forced_stop() : std::runtime_error("nlopt forced stop") {}
+  };
+
   //////////////////////////////////////////////////////////////////////
 
   class opt {
@@ -66,8 +79,9 @@ namespace nlopt {
       switch (ret) {
       case NLOPT_FAILURE: throw std::runtime_error("nlopt failure");
       case NLOPT_OUT_OF_MEMORY: throw std::bad_alloc();
-      case NLOPT_INVALID_ARGS: throw std::invalid_argument("nlopt");
-      case NLOPT_ROUNDOFF_LIMITED: throw std::runtime_error("nlopt roundoff");
+      case NLOPT_INVALID_ARGS: throw std::invalid_argument("nlopt invalid argument");
+      case NLOPT_ROUNDOFF_LIMITED: throw roundoff_limited();
+      case NLOPT_FORCED_STOP: throw forced_stop();
       default: break;
       }
     }