diff --git a/include/CoolPropLib.h b/include/CoolPropLib.h index 8000bf60..fb0d1a2f 100644 --- a/include/CoolPropLib.h +++ b/include/CoolPropLib.h @@ -146,7 +146,7 @@ EXPORT_CODE double CONVENTION K2F(double T_K); /** \brief Get the index for a parameter "T", "P", etc. * - * @returns index The index as a long + * @returns index The index as a long. If input is invalid, returns -1 */ EXPORT_CODE long CONVENTION get_param_index(const char *param); /** \brief Redirect all output that would go to console (stdout) to a file diff --git a/src/CoolPropLib.cpp b/src/CoolPropLib.cpp index 06d6439f..8cf8bd0d 100644 --- a/src/CoolPropLib.cpp +++ b/src/CoolPropLib.cpp @@ -228,7 +228,12 @@ EXPORT_CODE void CONVENTION set_debug_level(int level){ CoolProp::set_debug_level(level); } EXPORT_CODE long CONVENTION get_param_index(const char * param){ - return CoolProp::get_parameter_index(param); + try{ + return CoolProp::get_parameter_index(param); + } + catch(std::exception &){ + return -1; + } } EXPORT_CODE long CONVENTION get_global_param_string(const char *param, char * Output, int n) { @@ -249,7 +254,12 @@ EXPORT_CODE long CONVENTION get_global_param_string(const char *param, char * Ou } EXPORT_CODE long CONVENTION get_parameter_information_string(const char *param, char * Output, int n) { - int key = CoolProp::get_parameter_index(param); + try{ + int key = CoolProp::get_parameter_index(param); + } + catch(std::exception &){ + return 0; + } if (key >= 0){ std::string s = CoolProp::get_parameter_information(key, Output); if (s.size() < static_cast(n)){