Flow 1.0.1
Flow project: Full implementation reference.
error.cpp
Go to the documentation of this file.
1/* Flow
2 * Copyright 2023 Akamai Technologies, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the
5 * "License"); you may not use this file except in
6 * compliance with the License. You may obtain a copy
7 * of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in
12 * writing, software distributed under the License is
13 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14 * CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing
16 * permissions and limitations under the License. */
17
18/// @file
19#include "flow/error/error.hpp"
20
21namespace flow::error
22{
23
24// Implementations.
25
26Runtime_error::Runtime_error(const Error_code& err_code_or_success, util::String_view context) :
27 // This strange-looking dichotomy is explained in ###Rationale### in m_context_if_no_code doc header.
28 boost::system::system_error(err_code_or_success,
29 err_code_or_success
30 ? std::string(context)
31 : std::string()),
32 // code() == err_code_or_success, now.
33 m_context_if_no_code(code()
34 ? std::string()
35 : std::string(context))
36{
37 // Nothing.
38}
39
41 Runtime_error(Error_code(), context) // Our formal contract is to be equivalent to this.
42{
43 // Nothing.
44}
45
46const char* Runtime_error::what() const noexcept // Virtual.
47{
48 // This dichotomy is explained in ###Rationale### in m_context_if_no_code doc header. See ctor above also.
49 return code()
50 ? boost::system::system_error::what()
51 : m_context_if_no_code.c_str();
52}
53
54} // namespace flow::error
An std::runtime_error (which is an std::exception) that stores an Error_code.
Definition: error.hpp:49
Runtime_error(const Error_code &err_code_or_success, util::String_view context="")
Constructs Runtime_error.
Definition: error.cpp:26
const std::string m_context_if_no_code
This is a copy of context from ctor if !err_code_or_success; or unused otherwise.
Definition: error.hpp:120
const char * what() const noexcept override
Returns a message describing the exception.
Definition: error.cpp:46
Flow module that facilitates working with error codes and exceptions; essentially comprised of niceti...
Definition: error.cpp:22
Basic_string_view< char > String_view
Commonly used char-based Basic_string_view. See its doc header.
boost::system::error_code Error_code
Short-hand for a boost.system error code (which basically encapsulates an integer/enum error code and...
Definition: common.hpp:502