Skip to content

Commit

Permalink
Merge branch '89-catch_exc_in_C_API'
Browse files Browse the repository at this point in the history
Catch communication exceptions in C API to avoid crash.
Fixes #89
  • Loading branch information
szszszsz committed Jan 16, 2018
2 parents f72b672 + 1766a8e commit 27b8cd2
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 27b8cd2

Please sign in to comment.