SlHelpers
Toggle main menu visibility
Loading...
Searching...
No Matches
Exception.h
1
// SPDX-License-Identifier: GPL-2.0-only
2
3
#pragma once
4
5
#include <sstream>
6
#include <stdexcept>
7
#include <string_view>
8
9
namespace
SlHelpers {
10
22
class
[[nodiscard(
"Exception must be thrown"
)]] RuntimeException {
23
public
:
24
RuntimeException() =
default
;
26
RuntimeException
(std::string_view
str
) { m_oss <<
str
; }
27
28
struct
ThrowNow
{};
29
31
template
<
typename
T>
32
RuntimeException &
operator<<
(
const
T &msg) {
33
m_oss << msg;
34
return
*
this
;
35
}
36
38
std::string
str
()
const
{
return
m_oss.str(); }
39
41
auto
getRE
()
const
{
return
std::runtime_error(
str
()); }
42
44
[[noreturn]]
void
raise
()
const
{
throw
getRE
(); }
45
47
[[noreturn]]
void
operator<<
(
const
ThrowNow
&) {
raise
(); }
48
49
private
:
50
std::ostringstream m_oss;
51
};
52
53
inline
constexpr
RuntimeException::ThrowNow raise;
54
55
}
SlHelpers::RuntimeException::raise
void raise() const
Create and throw std::runtime_error.
Definition
Exception.h:44
SlHelpers::RuntimeException::RuntimeException
RuntimeException(std::string_view str)
Construct new RuntimeException, having str as the initial exception string.
Definition
Exception.h:26
SlHelpers::RuntimeException::getRE
auto getRE() const
Create and return std::runtime_error.
Definition
Exception.h:41
SlHelpers::RuntimeException::operator<<
void operator<<(const ThrowNow &)
Create and throw std::runtime_error.
Definition
Exception.h:47
SlHelpers::RuntimeException::operator<<
RuntimeException & operator<<(const T &msg)
Add more to the exception string.
Definition
Exception.h:32
SlHelpers::RuntimeException::str
std::string str() const
Return the stored exception string.
Definition
Exception.h:38
SlHelpers::RuntimeException::ThrowNow
Definition
Exception.h:28
include
helpers
Exception.h
Generated by
1.17.0