Skip to content

Commit 778ac0e

Browse files
committed
change exception generator
1 parent 5b4e9a3 commit 778ac0e

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

include/modbuscpp/details/exception.hpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

source/response.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ void response::decode(const packet_t& packet) {
9191
case internal::stage::error: {
9292
// decode the packet
9393
auto exc = packet.at(header_length + 1);
94-
throw_exception(static_cast<constants::exception_code>(exc), function(),
95-
header());
94+
throw generate_exception(static_cast<constants::exception_code>(exc),
95+
function(), header());
9696
} break;
9797
default:
9898
decode_passed(packet);

0 commit comments

Comments
 (0)