TRIQS/nda
2.0.0
Multi-dimensional array library for C++
Toggle main menu visibility
Loading...
Searching...
No Matches
exceptions.hpp
Go to the documentation of this file.
1
// Copyright (c) 2018--present, The Simons Foundation
2
// This file is part of TRIQS/nda and is licensed under the Apache License, Version 2.0.
3
// SPDX-License-Identifier: Apache-2.0
4
// See LICENSE in the root of this distribution for details.
5
10
11
#pragma once
12
13
#include "
./macros.hpp
"
14
15
#include <exception>
16
#include <sstream>
17
#include <string>
18
19
#define NDA_RUNTIME_ERROR throw nda::runtime_error{} << "Error at " << __FILE__ << " : " << __LINE__ << "\n\n"
20
21
#define NDA_ASSERT(X) \
22
if (!(X)) NDA_RUNTIME_ERROR << AS_STRING(X);
23
24
#define NDA_ASSERT2(X, ...) \
25
if (!(X)) NDA_RUNTIME_ERROR << AS_STRING(X) << "\n" << __VA_ARGS__;
26
27
namespace
nda {
28
35
class
runtime_error
:
public
std::exception {
36
// Accumulator for the error message.
37
std::stringstream acc;
38
39
// Error message.
40
mutable
std::string _what;
41
42
public
:
44
runtime_error
() noexcept : std::exception() {}
45
50
runtime_error
(
runtime_error
const
&err) noexcept : acc(err.acc.str()), _what(err._what) {}
51
53
~runtime_error
() noexcept override = default;
54
62
template <typename T>
63
runtime_error
&operator<<(T const &x) {
64
acc << x;
65
return
*
this
;
66
}
67
74
runtime_error
&
operator<<
(
const
char
*mess) {
75
(*this) << std::string(mess);
76
return
*
this
;
77
}
78
83
const
char
*
what
() const noexcept
override
{
84
_what = acc.str();
85
return
_what.c_str();
86
}
87
};
88
89
}
// namespace nda
nda::runtime_error::what
const char * what() const noexcept override
Override the virtual function what from std::exception to retrieve the accumulated error message.
Definition
exceptions.hpp:83
nda::runtime_error::runtime_error
runtime_error() noexcept
Default constructor.
Definition
exceptions.hpp:44
nda::runtime_error::~runtime_error
~runtime_error() noexcept override=default
Default destructor.
nda::runtime_error::runtime_error
runtime_error(runtime_error const &err) noexcept
Copy constructor to copy the contents of the error message accumulator.
Definition
exceptions.hpp:50
nda::runtime_error::operator<<
runtime_error & operator<<(const char *mess)
Accumulate error message.
Definition
exceptions.hpp:74
macros.hpp
Macros used in the nda library.
nda
exceptions.hpp
Generated by
1.17.0