diff --git a/ml.cpp b/ml.cpp index bf20ab3..f02b0d2 100644 --- a/ml.cpp +++ b/ml.cpp @@ -636,6 +636,10 @@ std::string MlError::description() const { return MlPerfMon::instance().callstack() + "error: the expression `" + cause->debug() + "` with message \"" + msg + "\""; } +const char * MlError::what() const noexcept { + return msg; +} + void MlEnvironment::combine(MlEnvironment const &other) { // Normally, I would use the `insert` method of the `map` class, // but it doesn't overwrite previously declared values for keys. @@ -1844,8 +1848,7 @@ MlValue sprintf(std::vector args, MlEnvironment &env) { if (args.size() < 1 || args.size() > 2) throw MlError(MlValue("sprintf", sprintf), env, args.size() > 2 ? TOO_MANY_ARGS : TOO_FEW_ARGS); - return MlValue::string( - mini_sprintf(args[0].as_string(), args.size() == 2 ? args[1].as_list() : std::vector{})); + return MlValue::string(mini_sprintf(args[0].as_string(), args.size() == 2 ? args[1].as_list() : std::vector{})); } // >>> (map (lambda (x) (+ x 10)) '(1 2 3 4 5 6)) diff --git a/ml.h b/ml.h index 5aac218..d6d2e84 100644 --- a/ml.h +++ b/ml.h @@ -81,6 +81,8 @@ public: // Get the printable error description. std::string description() const; + const char * what() const noexcept override; + private: MlValue *cause; MlEnvironment env;