.. _program_listing_file_include_zim_error.h: Program Listing for File error.h ================================ |exhale_lsh| :ref:`Return to documentation for file ` (``include/zim/error.h``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp /* * Copyright (C) 2020 Matthieu Gautier * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * is provided AS IS, WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and * NON-INFRINGEMENT. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * */ #ifndef ZIM_ERROR_H #define ZIM_ERROR_H #include "zim.h" #include "tools.h" #include #include namespace zim { class LIBZIM_API ZimFileFormatError : public std::runtime_error { public: explicit ZimFileFormatError(const std::string& msg) : std::runtime_error(msg) { } }; class LIBZIM_API InvalidType: public std::logic_error { public: explicit InvalidType(const std::string& msg) : std::logic_error(msg) {} }; class LIBZIM_API EntryNotFound : public std::runtime_error { public: explicit EntryNotFound(const std::string& msg) : std::runtime_error(msg) {} }; class LIBZIM_API CreatorError : public std::runtime_error { public: explicit CreatorError(const std::string& message) : std::runtime_error(message) {} }; class LIBZIM_API InvalidEntry : public CreatorError { public: explicit InvalidEntry(const std::string& message) : CreatorError(message) {} }; class LIBZIM_API IncoherentImplementationError : public CreatorError { public: explicit IncoherentImplementationError(const std::string& message) : CreatorError(message) {} }; class LIBZIM_API TitleIndexingError : public CreatorError { public: explicit TitleIndexingError(const std::string& message) : CreatorError(message) {} }; class LIBZIM_API AsyncError : public CreatorError { public: explicit AsyncError(const std::exception_ptr exception) : CreatorError(buildErrorMessage(exception)), m_exception(exception) {} [[noreturn]] void rethrow() const { std::rethrow_exception(m_exception); } private: // data std::exception_ptr m_exception; private: // function static std::string buildErrorMessage(const std::exception_ptr exception) { try { std::rethrow_exception(exception); } catch (const std::exception& e) { return Formatter() << "Asynchronous error: " << typeid(e).name() << std::endl << e.what(); } catch (...) { return "Unknown asynchronous exception"; } } }; class LIBZIM_API CreatorStateError : public CreatorError { public: explicit CreatorStateError() : CreatorError("Creator is in error state.") {} }; } #endif // ZIM_ERROR_H