| 31 | } |
| 32 | } |
| 33 | void HandleException(long* errcode, char* message_buffer, const long buffer_length) { |
| 34 | try { |
| 35 | throw; // Rethrow the error, and here we handle the error |
| 36 | } catch (CoolProp::HandleError& e) { |
| 37 | std::string errmsg = std::string("HandleError: ") + e.what(); |
| 38 | if (errmsg.size() < static_cast<std::size_t>(buffer_length)) { |
| 39 | *errcode = 1; |
| 40 | std::memcpy(message_buffer, errmsg.c_str(), errmsg.size() + 1); // guarded above: size + null fits |
| 41 | } else { |
| 42 | *errcode = 2; |
| 43 | } |
| 44 | } catch (CoolProp::CoolPropBaseError& e) { |
| 45 | std::string errmsg = std::string("Error: ") + e.what(); |
| 46 | if (errmsg.size() < static_cast<std::size_t>(buffer_length)) { |
| 47 | *errcode = 1; |
| 48 | std::memcpy(message_buffer, errmsg.c_str(), errmsg.size() + 1); // guarded above: size + null fits |
| 49 | } else { |
| 50 | *errcode = 2; |
| 51 | } |
| 52 | } catch (...) { |
| 53 | *errcode = 3; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | // FP-exception handling at the C-interface boundary lives in CoolProp/FPUGuard.h |
| 58 | // (CoolProp::fpu_guard). It masks FP exceptions on entry so trapping hosts |
no test coverage detected