Sauce-0.10.1
A C++ Dependency Injection Framework
pending_thrower.h
1#ifndef SAUCE_INTERNAL_PENDING_THROWER_H_
2#define SAUCE_INTERNAL_PENDING_THROWER_H_
3
4namespace sauce {
5namespace internal {
6
7typedef void (*PendingThrow)();
8
15template<typename Exception>
16void pendingThrowFactory() {
17 throw Exception();
18}
19
23class PendingThrower { // Tempted to call it PendingThrowDown
24 PendingThrow pending;
25
26public:
27
29 pending(NULL) {}
30
38 template<typename Exception>
39 void throwLater() {
40 pending = &pendingThrowFactory<Exception>;
41 }
42
47 PendingThrow toThrow = clear();
48 if (toThrow) {
49 toThrow();
50 }
51 }
52
58 PendingThrow clear() {
59 PendingThrow toThrow = pending;
60 pending = NULL;
61 return toThrow;
62 }
63};
64
65}
66
67namespace i = ::sauce::internal;
68
69}
70
71#endif // SAUCE_INTERNAL_PENDING_THROWER_H_
A mixin to defer and throw pending exceptions.
Definition: pending_thrower.h:23
void throwLater()
Save an exception of the given type to throw when it is safe.
Definition: pending_thrower.h:39
PendingThrow clear()
Clear and return any saved exception.
Definition: pending_thrower.h:58
void throwAnyPending()
Throw and clear any saved exception.
Definition: pending_thrower.h:46