iceoryx2
C++ Language Bindings
Loading...
Searching...
No Matches
error_kind.hpp
Go to the documentation of this file.
1// Copyright (c) 2023 by Apex.AI Inc. All rights reserved.
2// Copyright (c) 2025 Contributors to the Eclipse Foundation
3//
4// See the NOTICE file(s) distributed with this work for additional
5// information regarding copyright ownership.
6//
7// This program and the accompanying materials are made available under the
8// terms of the Apache Software License 2.0 which is available at
9// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
10// which is available at https://opensource.org/licenses/MIT.
11//
12// SPDX-License-Identifier: Apache-2.0 OR MIT
13
14#ifndef IOX2_BB_REPORTING_ERROR_REPORTING_ERROR_KIND_HPP
15#define IOX2_BB_REPORTING_ERROR_REPORTING_ERROR_KIND_HPP
16
17#include <type_traits>
18
19namespace iox2 {
20namespace legacy {
21namespace er {
22
23// Tag types for mandatory fatal error categories that always exist.
24// They have the suffix "Kind" to allow using the prefix as the actual error type.
25// The split between error type and error kind is intentional to allow emitting the same error
26// type with a different kind if needed, similar to categorical logging.
27//
28// In addition, this has the advantage to be more explicit at reporting site instead of hiding
29// the information in a function name or the error itself.
30
31struct FatalKind {
32 static constexpr char const* name = "Fatal Error";
33};
34
36 static constexpr char const* name = "Assert Violation";
37};
38
40 static constexpr char const* name = "Enforce Violation";
41};
42
43template <class T>
44struct IsFatal : public std::false_type {
47};
48
49// This specialization makes it impossible to specialize them differently elsewhere,
50// as this would lead to a compilation error.
51// This enforces that these errors are always fatal in the sense that they cause panic and abort.
52template <>
53struct IsFatal<FatalKind> : public std::true_type { };
54
55template <>
56struct IsFatal<AssertViolationKind> : public std::true_type { };
57
58template <>
59struct IsFatal<EnforceViolationKind> : public std::true_type { };
60
61// The function syntax is more useful if there is already a value (instead of only a type).
62// It must be consistent with the type trait, i.e. yield the same boolean value.
63template <class Kind>
64bool constexpr isFatal(Kind) {
66}
67
68template <>
72
73template <>
77
78template <>
82
83// indicates serious condition, unable to continue
84constexpr FatalKind FATAL;
85
86// indicates a bug (check only active in debug builds)
88
89// indicates a bug (check always active)
91
92} // namespace er
93} // namespace legacy
94} // namespace iox2
95
96#endif // IOX2_BB_REPORTING_ERROR_REPORTING_ERROR_LOGGING_HPP
bool constexpr isFatal(Kind)
constexpr AssertViolationKind ASSERT_VIOLATION
constexpr FatalKind FATAL
bool constexpr isFatal< AssertViolationKind >(AssertViolationKind)
bool constexpr isFatal< FatalKind >(FatalKind)
constexpr EnforceViolationKind ENFORCE_VIOLATION
bool constexpr isFatal< EnforceViolationKind >(EnforceViolationKind)
constexpr bool always_false_v
Helper value to bind a static_assert to a type.
static constexpr char const * name
static constexpr char const * name
static constexpr char const * name