Provide a compliant standard is_error_condition_enum
trait.
More...
- Outline
-
-
- Purpose:
- Provide a compliant standard
is_error_condition_enum
trait.
-
- Classes:
bsl::is_error_condition_enum | standard complaint is_error_condition_enum |
-
- Macros:
BSL_IS_ERROR_CONDITION_ENUM_NAMESPACE | namespace to specialize the triat |
- Canonical Header:
- bsl_system_error.h
-
- Description:
- This component defines a class template,
bsl::is_error_condition_enum
, intended to be specialized for enumeration types that are designated as error conditions for the <system_error>
facility. In C++11 mode, the vendor-supplied <system_error>
implementation is used instead, and the corresponding names from std
are imported into bsl
. This component also defines a macro, BSL_IS_ERROR_CONDITION_ENUM_NAMESPACE
, to be used as the namespace in which to write specializations of is_error_condition_enum
.
-
- Usage:
- In this section we show intended use of this component.
-
- Example 1: Dedicated Error Values:
- Suppose we have a dedicated system with a set of possible errors, and we want to be able to throw descriptive exceptions when an error occurs. We need to work with the
<system_error>
facility to support this, starting by marking the enumeration type that defines the error literals as eligible to participate. We can use bsl::is_error_condition
to do this.
- First, we define the set of error values for our system.
struct CarError {
enum Enum {
k_CAR_WHEELS_CAME_OFF = 1,
k_CAR_ENGINE_FELL_OUT = 2
};
};
Then, we enable the trait marking this as an error condition. Finally, we verify that the trait marks our type as eligible. assert(is_error_condition_enum<CarError::Enum>::value);