aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2018-01-16 16:29:51 +0100
committerSzczepan Zalega <szczepan@nitrokey.com>2018-01-16 16:29:51 +0100
commit27b8cd235494dc53e7c10881da13400f0ddb1d97 (patch)
tree8691e9f247e3f6a8062e2a806e1d24bb17e46bcc
parentf72b672ff5a4df6bb549146bb7fa54b2b718728d (diff)
parent1766a8ef52aecffb2e3582d96ba67cd3a5750926 (diff)
downloadlibnitrokey-27b8cd235494dc53e7c10881da13400f0ddb1d97.tar.gz
libnitrokey-27b8cd235494dc53e7c10881da13400f0ddb1d97.tar.bz2
Merge branch '89-catch_exc_in_C_API'
Catch communication exceptions in C API to avoid crash. Fixes #89
-rw-r--r--NK_C_API.cc14
1 files changed, 14 insertions, 0 deletions
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<decltype(func())>(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;