diff --git a/src/Variable.h b/src/Variable.h index 75acf72..4ab4853 100644 --- a/src/Variable.h +++ b/src/Variable.h @@ -68,7 +68,13 @@ class variable { variable&operator=(std::nullptr_t) { r_value() = ""; data->_type = VARTYPE_NULL; return *this;} template - T as() const { return typecast::variable_cast(*this); } + T as() const { + try { + return typecast::variable_cast(*this); + } catch(std::exception& ex) { + throw std::invalid_argument{"failed to parse " + this->r_key() + " as " + typeid(T).name() + " (" + ex.what() + ")"}; + } + } std::string string() const { return as(); } //fast template //TODO more secure and not just try and fail