@@ -227,33 +227,34 @@ template <constants::exception_code modbus_exception> class internal
227227};
228228} // namespace ex
229229
230- inline void throw_exception (constants::exception_code ec,
231- constants::function_code function,
232- const header_t & request_header) {
230+ inline auto generate_exception (constants::exception_code ec,
231+ constants::function_code function,
232+ const header_t & request_header)
233+ -> std::exception {
233234 switch (ec) {
234235 case constants::exception_code::illegal_function:
235- throw ex::illegal_function (function, request_header);
236+ return ex::illegal_function (function, request_header);
236237 case constants::exception_code::illegal_data_address:
237- throw ex::illegal_data_address (function, request_header);
238+ return ex::illegal_data_address (function, request_header);
238239 case constants::exception_code::illegal_data_value:
239- throw ex::illegal_data_value (function, request_header);
240+ return ex::illegal_data_value (function, request_header);
240241 case constants::exception_code::server_device_failure:
241- throw ex::server_device_failure (function, request_header);
242+ return ex::server_device_failure (function, request_header);
242243 case constants::exception_code::acknowledge:
243- throw ex::acknowledge (function, request_header);
244+ return ex::acknowledge (function, request_header);
244245 case constants::exception_code::server_device_busy:
245- throw ex::server_device_busy (function, request_header);
246+ return ex::server_device_busy (function, request_header);
246247 case constants::exception_code::negative_acknowledge:
247- throw ex::negative_acknowledge (function, request_header);
248+ return ex::negative_acknowledge (function, request_header);
248249 case constants::exception_code::memory_parity_error:
249- throw ex::memory_parity_error (function, request_header);
250+ return ex::memory_parity_error (function, request_header);
250251 case constants::exception_code::gateway_path_unavailable:
251- throw ex::gateway_path_unavailable (function, request_header);
252+ return ex::gateway_path_unavailable (function, request_header);
252253 case constants::exception_code::gateway_target_device_failed_to_respond:
253- throw ex::gateway_target_device_failed_to_respond (function,
254- request_header);
254+ return ex::gateway_target_device_failed_to_respond (function,
255+ request_header);
255256 default :
256- throw ex::bad_exception ();
257+ return ex::bad_exception ();
257258 }
258259}
259260} // namespace modbus
0 commit comments