-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexceptions.hh
48 lines (35 loc) · 970 Bytes
/
exceptions.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef _AMANZI_EXCEPTIONS_H_
#define _AMANZI_EXCEPTIONS_H_
#include <string>
#include <stdlib.h>
namespace Exceptions {
// A Base exception class for exceptions generated by the Amanzi code.
class Amanzi_exception : public std::exception {
};
// Enumerates possible ways to handle exceptions.
enum Exception_action
{
RAISE,
ABORT
};
// Functions for setting and querying the current exception behavior.
void set_exception_behavior_raise();
void set_exception_behavior_abort();
void set_exception_behavior(Exception_action);
Exception_action exception_behavior();
} // namespace Exceptions
namespace {
Exceptions::Exception_action behavior = Exceptions::RAISE;
}
namespace Exceptions {
// Either raise the given exception or abort, depending on the value of behavior.
template <typename E>
void amanzi_throw(const E& exception)
{
if (behavior == Exceptions::RAISE)
throw exception;
else
abort();
}
} // namespace Exceptions
#endif