cpp-common: Add common exceptions
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Tue, 19 Apr 2022 20:49:47 +0000 (16:49 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 11 Sep 2023 15:24:02 +0000 (11:24 -0400)
Add `bt2_common::{End, Error, MemoryError, TryAgain}` exception classes
to use in in-tree components and elsewhere. Each exception inherits a
C++ standard exception that I believe matches more closely in meaning.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I7335465f2377e032ae9706108708e35d78d38e6e
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7918
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10809
Tested-by: jenkins <jenkins@lttng.org>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>

src/cpp-common/Makefile.am
src/cpp-common/exc.hpp [new file with mode: 0644]

index 761a23e0c4b8931873536f3d4ddde40a3fc60504..bcf43c220cd1018e34b07f4bec522b82340ac305 100644 (file)
@@ -1,3 +1,8 @@
 # SPDX-License-Identifier: MIT
 
-EXTRA_DIST = bt2 optional.hpp string_view.hpp nlohmann/json.hpp log-cfg.hpp
+EXTRA_DIST = bt2 \
+       exc.hpp \
+       log-cfg.hpp \
+       nlohmann/json.hpp \
+       optional.hpp \
+       string_view.hpp
diff --git a/src/cpp-common/exc.hpp b/src/cpp-common/exc.hpp
new file mode 100644 (file)
index 0000000..f624c26
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2022 Francis Deslauriers <francis.deslauriers@efficios.com>
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#ifndef BABELTRACE_CPP_COMMON_EXC_HPP
+#define BABELTRACE_CPP_COMMON_EXC_HPP
+
+#include <exception>
+#include <string>
+#include <new>
+#include <stdexcept>
+
+namespace bt2_common {
+
+/*
+ * End of iteration.
+ */
+class End : public std::exception
+{
+public:
+    explicit End() noexcept : std::exception {}
+    {
+    }
+};
+
+/*
+ * General error.
+ */
+class Error : public std::runtime_error
+{
+public:
+    explicit Error(std::string msg = "Error") : std::runtime_error {std::move(msg)}
+    {
+    }
+};
+
+/*
+ * Memory error.
+ */
+class MemoryError : public std::bad_alloc
+{
+public:
+    explicit MemoryError() noexcept : std::bad_alloc {}
+    {
+    }
+};
+
+/*
+ * Not available right now: try again later.
+ */
+class TryAgain : public std::exception
+{
+public:
+    explicit TryAgain() noexcept : std::exception {}
+    {
+    }
+};
+
+} /* namespace bt2_common */
+
+#endif /* BABELTRACE_CPP_COMMON_EXC_HPP */
This page took 0.025214 seconds and 4 git commands to generate.