diff options
| author | Szczepan Zalega <szczepan@nitrokey.com> | 2018-01-16 16:11:35 +0100 | 
|---|---|---|
| committer | Szczepan Zalega <szczepan@nitrokey.com> | 2018-01-16 16:11:35 +0100 | 
| commit | 1766a8ef52aecffb2e3582d96ba67cd3a5750926 (patch) | |
| tree | 78a02b9d6cae4a300397680e97abe5cd257a76f8 | |
| parent | ca7e766e9280f8f1a779a18f463ad398199497f1 (diff) | |
| download | libnitrokey-1766a8ef52aecffb2e3582d96ba67cd3a5750926.tar.gz libnitrokey-1766a8ef52aecffb2e3582d96ba67cd3a5750926.tar.bz2 | |
Catch DeviceCommunication exceptions in C API
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
| -rw-r--r-- | NK_C_API.cc | 14 | 
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; | 
