DFT-EFE
 
Loading...
Searching...
No Matches
Exceptions.h
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (c) 2021. *
3 * The Regents of the University of Michigan and DFT-EFE developers. *
4 * *
5 * This file is part of the DFT-EFE code. *
6 * *
7 * DFT-EFE is free software: you can redistribute it and/or modify *
8 * it under the terms of the Lesser GNU General Public License as *
9 * published by the Free Software Foundation, either version 3 of *
10 * the License, or (at your option) any later version. *
11 * *
12 * DFT-EFE is distributed in the hope that it will be useful, but *
13 * WITHOUT ANY WARRANTY; without even the implied warranty *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
15 * See the Lesser GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License at the top level of DFT-EFE distribution. If not, see *
19 * <https://www.gnu.org/licenses/>. *
20 ******************************************************************************/
21
22/*
23 * @author Bikash Kanungo
24 */
25#ifndef dftefeExceptions_h
26#define dftefeExceptions_h
27
28#include <string>
29#include <stdexcept>
86#undef DFTEFE_Assert
87#undef DFTEFE_AssertWithMsg
88
89#if defined(DFTEFE_DISABLE_ASSERT) || \
90 (!defined(DFTEFE_ENABLE_ASSERT) && defined(NDEBUG))
91# include <assert.h> // .h to support old libraries w/o <cassert> - effect is the same
92# define DFTEFE_Assert(expr) ((void)0)
93# define DFTEFE_AssertWithMsg(expr, msg) ((void)0)
94
95#elif defined(DFTEFE_ENABLE_ASSERT) && defined(NDEBUG)
96# undef NDEBUG // disabling NDEBUG to forcibly enable assert for sources that
97 // set DFTEFE_ENABLE_ASSERT even when in release mode (with
98 // NDEBUG)
99# include <assert.h> // .h to support old libraries w/o <cassert> - effect is the same
100# include <iostream>
101# define DFTEFE_Assert(expr) assert(expr)
102# define DFTEFE_AssertWithMsg(expr, msg) \
103 do \
104 { \
105 if (!(expr)) \
106 { \
107 std::cerr << (msg) << std::endl; \
108 assert(false); \
109 } \
110 } \
111 while (0)
112
113#else
114# include <assert.h> // .h to support old libraries w/o <cassert> - effect is the same
115# include <iostream>
116# define DFTEFE_Assert(expr) assert(expr)
117# define DFTEFE_AssertWithMsg(expr, msg) \
118 do \
119 { \
120 if (!(expr)) \
121 { \
122 std::cerr << (msg) << std::endl; \
123 assert(false); \
124 } \
125 } \
126 while (0)
127
128#endif
129
130#if defined(DFTEFE_WITH_DEVICE)
131# ifdef DFTEFE_WITH_DEVICE_LANG_CUDA
133# elif DFTEFE_WITH_DEVICE_LANG_HIP
135# elif DFTEFE_WITH_DEVICE_LANG_SYCL
137# endif
138#endif
139
140namespace dftefe
141{
142 namespace utils
143 {
144 typedef std::logic_error LogicError;
145 typedef std::invalid_argument InvalidArgument;
146 typedef std::domain_error DomainError;
147 typedef std::length_error LengthError;
148 typedef std::out_of_range OutOfRangeError;
149 typedef std::runtime_error RuntimeError;
150 typedef std::overflow_error OverflowError;
151 typedef std::underflow_error UnderflowError;
152
153 void
154 throwException(bool condition, std::string msg = "");
155
156 template <class T>
157 void
158 throwException(bool condition, std::string msg = "");
159
160 } // namespace utils
161} // namespace dftefe
162#include "Exceptions.t.cpp"
163#endif // dftefeExceptions_h
std::runtime_error RuntimeError
Definition: Exceptions.h:149
std::domain_error DomainError
Definition: Exceptions.h:146
std::underflow_error UnderflowError
Definition: Exceptions.h:151
std::out_of_range OutOfRangeError
Definition: Exceptions.h:148
void throwException(bool condition, std::string msg)
Definition: Exceptions.cpp:56
std::logic_error LogicError
Definition: Exceptions.h:144
std::length_error LengthError
Definition: Exceptions.h:147
std::overflow_error OverflowError
Definition: Exceptions.h:150
std::invalid_argument InvalidArgument
Definition: Exceptions.h:145
dealii includes
Definition: AtomFieldDataSpherical.cpp:31