Toolbox snapshot
The Reactive C++ Toolbox
Loading...
Searching...
No Matches
Exception.cpp
Go to the documentation of this file.
1// The Reactive C++ Toolbox.
2// Copyright (C) 2013-2019 Swirly Cloud Limited
3// Copyright (C) 2021 Reactive Markets Limited
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
17#include "Exception.hpp"
18
19namespace toolbox {
20inline namespace util {
21using namespace std;
22namespace {
23thread_local ErrMsg err_msg_;
24} // namespace
25
27: runtime_error{ec.message()}
28, ec_{ec}
29{
30}
31
32Exception::Exception(int err, const error_category& ecat)
33: Exception{error_code{err, ecat}}
34{
35}
36
37Exception::Exception(error_code ec, std::string_view what)
38: runtime_error{string{what}}
39, ec_{ec}
40{
41}
42
43Exception::Exception(int err, const error_category& ecat, std::string_view what)
44: Exception{error_code{err, ecat}, what}
45{
46}
47
48Exception::~Exception() = default;
49
50void Exception::to_json(ostream& os, int code, const char* message)
51{
52 os << "{\"code\":" << code //
53 << ",\"message\":\"" << message //
54 << "\"}";
55}
56
58{
60 return err_msg_;
61}
62
63} // namespace util
64} // namespace toolbox
const std::error_code & code() const noexcept
Returns the error code.
Definition Exception.hpp:66
static void to_json(std::ostream &os, int code, const char *message)
Definition Exception.cpp:50
Exception(std::error_code ec=std::error_code())
Definition Exception.cpp:26
void reset() noexcept
Reset the current position back to the beginning of the buffer.
Definition Stream.hpp:200
STL namespace.
ErrMsg & err_msg() noexcept
Definition Exception.cpp:57
OStaticStream< MaxErrSize > ErrMsg
Definition Exception.hpp:28
constexpr auto bind() noexcept
Definition Slot.hpp:92