From 1766a8ef52aecffb2e3582d96ba67cd3a5750926 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Tue, 16 Jan 2018 16:11:35 +0100 Subject: Catch DeviceCommunication exceptions in C API Signed-off-by: Szczepan Zalega --- NK_C_API.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/NK_C_API.cc b/NK_C_API.cc index f86ce47..6afce74 100644 --- a/NK_C_API.cc +++ b/NK_C_API.cc @@ -64,6 +64,9 @@ uint8_t * get_with_array_result(T func){ catch (LibraryException & libraryException){ NK_last_command_status = libraryException.exception_id(); } + catch (const DeviceCommunicationException &deviceException){ + NK_last_command_status = 256-deviceException.getType(); + } return nullptr; } @@ -79,6 +82,9 @@ const char* get_with_string_result(T func){ catch (LibraryException & libraryException){ NK_last_command_status = libraryException.exception_id(); } + catch (const DeviceCommunicationException &deviceException){ + NK_last_command_status = 256-deviceException.getType(); + } return ""; } @@ -94,6 +100,9 @@ auto get_with_result(T func){ catch (LibraryException & libraryException){ NK_last_command_status = libraryException.exception_id(); } + catch (const DeviceCommunicationException &deviceException){ + NK_last_command_status = 256-deviceException.getType(); + } return static_cast(0); } @@ -140,6 +149,11 @@ extern "C" { NK_last_command_status = commandFailedException.last_command_status; return commandFailedException.last_command_status; } + catch (const DeviceCommunicationException &deviceException){ + NK_last_command_status = 256-deviceException.getType(); + cerr << deviceException.what() << endl; + return 0; + } catch (std::runtime_error &e) { cerr << e.what() << endl; return 0; -- cgit v1.2.3