Toolbox
snapshot
The Reactive C++ Toolbox
Loading...
Searching...
No Matches
toolbox
util
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
19
namespace
toolbox
{
20
inline
namespace
util {
21
using namespace
std
;
22
namespace
{
23
thread_local
ErrMsg
err_msg_
;
24
}
// namespace
25
26
Exception::Exception
(error_code
ec
)
27
: runtime_error{
ec
.
message
()}
28
, ec_{
ec
}
29
{
30
}
31
32
Exception::Exception
(
int
err
,
const
error_category&
ecat
)
33
:
Exception
{error_code{
err
,
ecat
}}
34
{
35
}
36
37
Exception::Exception
(error_code
ec
, std::string_view
what
)
38
: runtime_error{string{
what
}}
39
, ec_{
ec
}
40
{
41
}
42
43
Exception::Exception
(
int
err
,
const
error_category&
ecat
, std::string_view
what
)
44
:
Exception
{error_code{
err
,
ecat
},
what
}
45
{
46
}
47
48
Exception::~Exception
() =
default
;
49
50
void
Exception::to_json
(ostream& os,
int
code,
const
char
*
message
)
51
{
52
os <<
"{\"code\":"
<<
code
//
53
<<
",\"message\":\""
<<
message
//
54
<<
"\"}"
;
55
}
56
57
ErrMsg
&
err_msg
()
noexcept
58
{
59
err_msg_
.
reset
();
60
return
err_msg_
;
61
}
62
63
}
// namespace util
64
}
// namespace toolbox
toolbox::util::Exception
Definition
Exception.hpp:30
toolbox::util::Exception::code
const std::error_code & code() const noexcept
Returns the error code.
Definition
Exception.hpp:66
toolbox::util::Exception::to_json
static void to_json(std::ostream &os, int code, const char *message)
Definition
Exception.cpp:50
toolbox::util::Exception::Exception
Exception(std::error_code ec=std::error_code())
Definition
Exception.cpp:26
toolbox::util::Exception::~Exception
~Exception() override
toolbox::OStaticStream
Definition
Stream.hpp:173
toolbox::util::OStaticStream::reset
void reset() noexcept
Reset the current position back to the beginning of the buffer.
Definition
Stream.hpp:200
std
STL namespace.
toolbox::util::err_msg
ErrMsg & err_msg() noexcept
Definition
Exception.cpp:57
toolbox::util::ErrMsg
OStaticStream< MaxErrSize > ErrMsg
Definition
Exception.hpp:28
toolbox::util::bind
constexpr auto bind() noexcept
Definition
Slot.hpp:92
toolbox
Definition
Benchmark.cpp:26
Exception.hpp
Generated by
1.9.8