From 8a6adddc161e133fdf1f02f63accf96bcdb7485a Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Thu, 18 Nov 2021 13:57:34 +0400 Subject: [PATCH] Non-throwing Book::getDefaultIllustration() --- include/book.h | 4 ++++ src/book.cpp | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/book.h b/include/book.h index c395ffce..4a8c8a7d 100644 --- a/include/book.h +++ b/include/book.h @@ -143,6 +143,10 @@ class Book bool m_readOnly = false; uint64_t m_size = 0; std::vector> m_illustrations; + + // Used as the return value of getDefaultIllustration() when no default + // illustration is found in the book + static const Illustration missingDefaultIllustration; }; } diff --git a/src/book.cpp b/src/book.cpp index 3074a843..35370bff 100644 --- a/src/book.cpp +++ b/src/book.cpp @@ -231,6 +231,8 @@ void Book::setPath(const std::string& path) : path; } +const Book::Illustration Book::missingDefaultIllustration; + const Book::Illustration& Book::getDefaultIllustration() const { for ( const auto& ilPtr : m_illustrations ) { @@ -238,7 +240,7 @@ const Book::Illustration& Book::getDefaultIllustration() const return *ilPtr; } } - throw std::runtime_error("No default illustration"); + return missingDefaultIllustration; } const std::string& Book::Illustration::getData() const