Woman, Life, Freedom


Adaptive AUTOSAR
ARA public interface header documentation
error_code.h
1#ifndef ERROR_CODE_H
2#define ERROR_CODE_H
3
4#include <string>
5#include "./error_domain.h"
6
7namespace ara
8{
9 namespace core
10 {
12 class ErrorCode final
13 {
14 private:
16 const ErrorDomain& mDomain;
17
18 public:
22 constexpr ErrorCode(
24 const ErrorDomain &domain) noexcept : mValue{value}, mDomain{domain}
25 {
26 }
27
28 ErrorCode() = delete;
29 ~ErrorCode() noexcept = default;
30
33 constexpr ErrorDomain::CodeType Value() const noexcept
34 {
35 return mValue;
36 }
37
40 constexpr ErrorDomain const &Domain() const noexcept
41 {
42 return mDomain;
43 }
44
47 std::string Message() const noexcept;
48
50 void ThrowAsException() const;
51
52 constexpr bool operator==(const ErrorCode &other) const noexcept
53 {
54 return mDomain == other.mDomain && mValue == other.mValue;
55 }
56
57 constexpr bool operator!=(const ErrorCode &other) const noexcept
58 {
59 return mDomain != other.mDomain || mValue != other.mValue;
60 }
61 };
62 }
63}
64
65#endif
A wrapper around the raw error code in a specific ErrorDomain.
Definition: error_code.h:13
std::string Message() const noexcept
Get error message.
Definition: error_code.cpp:8
constexpr ErrorCode(ErrorDomain::CodeType value, const ErrorDomain &domain) noexcept
Constructor.
Definition: error_code.h:22
constexpr ErrorDomain::CodeType Value() const noexcept
Get error code value.
Definition: error_code.h:33
constexpr ErrorDomain const & Domain() const noexcept
Get error code domain.
Definition: error_code.h:40
void ThrowAsException() const
Throw the error as an exception.
Definition: error_code.cpp:14
A class that defines the domain of an ErrorCode to avoid code interferences.
Definition: error_domain.h:14
uint32_t CodeType
Alias type of the error code.
Definition: error_domain.h:19