From ec16afc74753e3ee5d7ac8f4e1a0320ddc7ab262 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Mon, 3 Dec 2018 15:29:21 +1100 Subject: [PATCH] except: add custom base exception --- CMakeLists.txt | 2 ++ except.cpp | 17 +++++++++++++++++ except.hpp | 22 ++++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 except.cpp create mode 100644 except.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index cdfa1058..4f6b07f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -251,6 +251,8 @@ list ( encode/base.hpp endian.cpp endian.hpp + except.cpp + except.hpp exe.hpp extent.cpp extent.hpp diff --git a/except.cpp b/except.cpp new file mode 100644 index 00000000..fd813a6c --- /dev/null +++ b/except.cpp @@ -0,0 +1,17 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright 2018 Danny Robson + */ + +#include "except.hpp" + + +/////////////////////////////////////////////////////////////////////////////// +std::ostream& +cruft::operator<< (std::ostream &os, const cruft::error &obj) +{ + return obj.describe (os); +} diff --git a/except.hpp b/except.hpp new file mode 100644 index 00000000..698594b3 --- /dev/null +++ b/except.hpp @@ -0,0 +1,22 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright 2018 Danny Robson + */ + +#pragma once + +#include + +namespace cruft { + class error { + public: + virtual ~error () = default; + virtual std::ostream& describe (std::ostream&) const noexcept = 0; + }; + + + std::ostream& operator<< (std::ostream &os, error const&); +} \ No newline at end of file