Skip to content

Commit

Permalink
Catch DeviceCommunication exceptions in C API
Browse files Browse the repository at this point in the history
Signed-off-by: Szczepan Zalega <[email protected]>
  • Loading branch information
szszszsz committed Jan 16, 2018
1 parent ca7e766 commit 1766a8e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions NK_C_API.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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 "";
}

Expand All @@ -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<decltype(func())>(0);
}

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 1766a8e

Please sign in to comment.