From 9bc6b85e12d73a43b8d85ba109acff8778f4c08a Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Tue, 31 Jan 2017 18:17:58 +0100 Subject: Throw before communicating with device if it is not initialized Signed-off-by: Szczepan Zalega --- include/LibraryException.h | 2 -- include/device_proto.h | 7 ++++++- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/LibraryException.h b/include/LibraryException.h index 3c3fab4..e62788d 100644 --- a/include/LibraryException.h +++ b/include/LibraryException.h @@ -11,8 +11,6 @@ public: virtual uint8_t exception_id()= 0; }; - - class TargetBufferSmallerThanSource: public LibraryException { public: virtual uint8_t exception_id() override { diff --git a/include/device_proto.h b/include/device_proto.h index ba314f4..9401428 100644 --- a/include/device_proto.h +++ b/include/device_proto.h @@ -33,6 +33,7 @@ #define PWS_SEND_CR 3 #include +#include "DeviceCommunicationExceptions.h" namespace nitrokey { namespace proto { @@ -217,6 +218,10 @@ namespace nitrokey { Log::instance()(__PRETTY_FUNCTION__, Loglevel::DEBUG_L2); + if (dev == nullptr){ + throw DeviceNotConnected("Device not initialized"); + } + int status; OutgoingPacket outp; ResponsePacket resp; @@ -320,7 +325,7 @@ namespace nitrokey { clear_packet(outp); if (status <= 0) - throw std::runtime_error( //FIXME replace with CriticalErrorException + throw DeviceReceivingFailure( //FIXME replace with CriticalErrorException std::string("Device error while executing command ") + std::to_string(status)); -- cgit v1.2.3