1
1
//
2
- // Error_Handling_Impl .h
2
+ // ExceptionHandling_Impl .h
3
3
// GUI Widget Library
4
4
//
5
+ // Implementation for the ExceptionHandler class.
6
+ //
5
7
// Created by Nathan Daly on 2/18/13.
6
- // Copyright (c) 2013 Lions Entertainment. All rights reserved .
8
+ // Referenced from .
7
9
//
8
10
9
- #ifndef GUI_Error_Handling_Impl_h
10
- #define GUI_Error_Handling_Impl_h
11
+ #ifndef GUI_Exception_Handling_Impl_h
12
+ #define GUI_Exception_Handling_Impl_h
11
13
12
14
#include < vector>
13
15
@@ -17,36 +19,36 @@ namespace GUIExceptionHandling {
17
19
template <typename Exception_t, typename Handler_t>
18
20
class ExceptionHandler_Impl ;
19
21
20
-
22
+
21
23
// Abstract ExceptionHandler Base Class.
22
24
// Derived class will be templated for Error type and Handler type.
23
25
class ExceptionHandler {
24
26
private: // Everything is private so that this can only be used as a base
25
27
// class for the ExceptionHandler_Impl class.
26
-
28
+
27
29
28
30
// A virtual function cannot be templated, so we require that try_catch,
29
31
// below, use a vector::iterator.
30
32
typedef std::vector<ExceptionHandler*>::iterator ExceptionHandlerIter_t;
31
33
32
34
// Recursive function call to iterate through list and try-catch on
33
35
// currently thrown exception.
34
- virtual void try_catch (ExceptionHandlerIter_t begin,
35
- ExceptionHandlerIter_t end, bool &handled) = 0;
36
+ virtual void try_rethrow_catch (ExceptionHandlerIter_t begin,
37
+ ExceptionHandlerIter_t end, bool &handled)= 0;
36
38
37
39
38
40
// This is the public interface for interacting with ExceptionHandlers
39
41
template <typename InputIterator>
40
42
friend void call_exception_handlers_helper (InputIterator begin,
41
43
InputIterator end, bool handled);
42
-
44
+
43
45
// The only actual derived class that will use this class's functions.
44
46
template <typename Exception_t, typename Handler_t>
45
47
friend class ExceptionHandler_Impl ;
46
48
};
47
49
48
50
49
- // Implementation of ExceptionHandler. Nests try statements for all
51
+ // Implementation of ExceptionHandler. Nests try statements for all
50
52
// ExceptionHandlers passed in, and rethrows the current exception.
51
53
// Then each ExceptionHandler attempts to catch during the unravelling.
52
54
//
@@ -55,8 +57,8 @@ class ExceptionHandler {
55
57
template <typename Exception_t, typename Handler_t>
56
58
class ExceptionHandler_Impl : public ExceptionHandler {
57
59
private: // Everything is private, so that ExceptionHandler_Impl isn't
58
- // created anywhere but from create_exception_handler().
59
-
60
+ // created anywhere but from create_exception_handler().
61
+
60
62
61
63
// handler_ should be a callable entity s.t. handler_(Exception_t) is valid.
62
64
// NOTE: handler_ will be copied.
@@ -66,16 +68,16 @@ class ExceptionHandler_Impl : public ExceptionHandler {
66
68
// RESULT: handled will be set to true if any ExceptionHandler successfully
67
69
// handled the current exception.
68
70
// REQUIRES: this must be called from inside a catch{} block.
69
- virtual void try_catch (ExceptionHandlerIter_t begin,
70
- ExceptionHandlerIter_t end, bool &handled) {
71
+ virtual void try_rethrow_catch (ExceptionHandlerIter_t begin,
72
+ ExceptionHandlerIter_t end, bool &handled) {
71
73
72
74
// nest a try block for each ExceptionHandler
73
75
try {
74
76
if (begin == end) { // base case
75
77
throw ;
76
78
}
77
79
ExceptionHandler *next = *begin;
78
- next->try_catch (++begin, end, handled); // unravel until end
80
+ next->try_rethrow_catch (++begin, end, handled); // unravel until end
79
81
}
80
82
// Each ExceptionHandler gets a chance to try to catch the exception.
81
83
catch (const Exception_t &e) { // Will only catch if e is of Exception_t
@@ -93,7 +95,7 @@ class ExceptionHandler_Impl : public ExceptionHandler {
93
95
private:
94
96
Handler_t handler;
95
97
};
96
-
98
+
97
99
} // namespace GUIExceptionHandling
98
100
99
- #endif /* GUI_Error_Handling_Impl_h */
101
+ #endif /* GUI_Exception_Handling_Impl_h */
0 commit comments