From bfd56f73d422c1ec9c6d501437de60dd5504cafa Mon Sep 17 00:00:00 2001 From: Talley Lambert Date: Sun, 1 Dec 2024 18:36:02 -0500 Subject: [PATCH 1/2] implement std::exception for MetadataError --- MMDevice/ImageMetadata.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/MMDevice/ImageMetadata.h b/MMDevice/ImageMetadata.h index 212d7b084..ee27aeae1 100644 --- a/MMDevice/ImageMetadata.h +++ b/MMDevice/ImageMetadata.h @@ -55,6 +55,9 @@ class MetadataError return message_; } + /// Implements std::exception interface. + virtual const char* what() const throw() { return message_.c_str(); } + private: std::string message_; }; From 2ace58ce6dac0bcb8a211f0b99a0d0f8e675bc00 Mon Sep 17 00:00:00 2001 From: Talley Lambert Date: Mon, 2 Dec 2024 16:46:14 -0500 Subject: [PATCH 2/2] include key in error --- MMDevice/ImageMetadata.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/MMDevice/ImageMetadata.h b/MMDevice/ImageMetadata.h index ee27aeae1..7790b010b 100644 --- a/MMDevice/ImageMetadata.h +++ b/MMDevice/ImageMetadata.h @@ -67,6 +67,8 @@ class MetadataKeyError : public MetadataError public: MetadataKeyError() : MetadataError("Undefined metadata key") {} + MetadataKeyError(const char* key) : + MetadataError(("Undefined metadata key: " + std::string(key)).c_str()) {} ~MetadataKeyError() {} }; @@ -490,7 +492,7 @@ class Metadata if (it != tags_.end()) return it->second; else - throw MetadataKeyError(); + throw MetadataKeyError(key); } std::map tags_;