Skip to content

Commit c52f70b

Browse files
committed
Clarified docs a bit and improved the header docs for Exception Handling
files.
1 parent 551a600 commit c52f70b

File tree

2 files changed

+34
-26
lines changed

2 files changed

+34
-26
lines changed

GUIExceptionHandling.h

+15-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
//
2-
// ErrorHandling.h
2+
// ExceptionHandling.h
33
// GUI Widget Library
44
//
5+
// Definitions for the Exception Handling functions:
6+
// ExceptionHandler* create_exception_handler(const Handler_t &handler);
7+
// void call_exception_handlers(InputIterator begin, InputIterator end);
8+
//
59
// Created by Nathan Daly on 12/14/12.
610
// Copyright (c) 2012 Lions Entertainment. All rights reserved.
711
//
812

9-
#ifndef GUI_ErrorHandling_h
10-
#define GUI_ErrorHandling_h
1113

12-
#include "GUIExceptionHandling_Impl.h" // For ErrorCatcher and ErrorCatcher_Impl
14+
#ifndef GUI_Exception_Handling_h
15+
#define GUI_Exception_Handling_h
16+
17+
#include "GUIExceptionHandling_Impl.h" // Contains details irrelevant to clients
1318

1419
namespace GUIExceptionHandling {
1520

@@ -21,9 +26,9 @@ ExceptionHandler* create_exception_handler(const Handler_t &handler) {
2126
return new ExceptionHandler_Impl<Exception_t, Handler_t>(handler);
2227
}
2328

24-
// REQUIRES: This function MUST be called from within a catch(){} block!
2529
// Loop through error handlers and handle any errors. If no handler matches
2630
// the error, it will be rethrown out of the function.
31+
// REQUIRES: This function MUST be called from within a catch(){} block!
2732
template <typename InputIterator>
2833
void call_exception_handlers(InputIterator begin, InputIterator end) {
2934
call_exception_handlers_helper(begin, end, false);
@@ -35,11 +40,12 @@ void call_exception_handlers_helper(InputIterator begin,
3540

3641
try {
3742
// Create a vector of handlers
38-
// (Since try_catch is virtual, it cannot be templated,
39-
// so it requires a vector.)
43+
// (Since try_rethrow_catch is virtual, it cannot be templated,
44+
// so it requires a vector.)
4045
std::vector<ExceptionHandler*> catchers(begin, end);
4146

42-
catchers.front()->try_catch(++catchers.begin(), catchers.end(), handled);
47+
catchers.front()->try_rethrow_catch(++catchers.begin(),
48+
catchers.end(), handled);
4349

4450
}
4551
catch (...) {
@@ -51,4 +57,4 @@ void call_exception_handlers_helper(InputIterator begin,
5157

5258
} // namespace GUIExceptionHandling
5359

54-
#endif /* GUI_ErrorHandling_h */
60+
#endif /* GUI_Exception_Handling_h */

GUIExceptionHandling_Impl.h

+19-17
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
//
2-
// Error_Handling_Impl.h
2+
// ExceptionHandling_Impl.h
33
// GUI Widget Library
44
//
5+
// Implementation for the ExceptionHandler class.
6+
//
57
// Created by Nathan Daly on 2/18/13.
6-
// Copyright (c) 2013 Lions Entertainment. All rights reserved.
8+
// Referenced from .
79
//
810

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
1113

1214
#include <vector>
1315

@@ -17,36 +19,36 @@ namespace GUIExceptionHandling {
1719
template <typename Exception_t, typename Handler_t>
1820
class ExceptionHandler_Impl;
1921

20-
22+
2123
// Abstract ExceptionHandler Base Class.
2224
// Derived class will be templated for Error type and Handler type.
2325
class ExceptionHandler {
2426
private: // Everything is private so that this can only be used as a base
2527
// class for the ExceptionHandler_Impl class.
26-
28+
2729

2830
// A virtual function cannot be templated, so we require that try_catch,
2931
// below, use a vector::iterator.
3032
typedef std::vector<ExceptionHandler*>::iterator ExceptionHandlerIter_t;
3133

3234
// Recursive function call to iterate through list and try-catch on
3335
// 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;
3638

3739

3840
// This is the public interface for interacting with ExceptionHandlers
3941
template <typename InputIterator>
4042
friend void call_exception_handlers_helper(InputIterator begin,
4143
InputIterator end, bool handled);
42-
44+
4345
// The only actual derived class that will use this class's functions.
4446
template <typename Exception_t, typename Handler_t>
4547
friend class ExceptionHandler_Impl;
4648
};
4749

4850

49-
// Implementation of ExceptionHandler. Nests try statements for all
51+
// Implementation of ExceptionHandler. Nests try statements for all
5052
// ExceptionHandlers passed in, and rethrows the current exception.
5153
// Then each ExceptionHandler attempts to catch during the unravelling.
5254
//
@@ -55,8 +57,8 @@ class ExceptionHandler {
5557
template <typename Exception_t, typename Handler_t>
5658
class ExceptionHandler_Impl : public ExceptionHandler {
5759
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+
6062

6163
// handler_ should be a callable entity s.t. handler_(Exception_t) is valid.
6264
// NOTE: handler_ will be copied.
@@ -66,16 +68,16 @@ class ExceptionHandler_Impl : public ExceptionHandler {
6668
// RESULT: handled will be set to true if any ExceptionHandler successfully
6769
// handled the current exception.
6870
// 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) {
7173

7274
// nest a try block for each ExceptionHandler
7375
try {
7476
if (begin == end) { // base case
7577
throw;
7678
}
7779
ExceptionHandler *next = *begin;
78-
next->try_catch(++begin, end, handled); // unravel until end
80+
next->try_rethrow_catch(++begin, end, handled); // unravel until end
7981
}
8082
// Each ExceptionHandler gets a chance to try to catch the exception.
8183
catch(const Exception_t &e) { // Will only catch if e is of Exception_t
@@ -93,7 +95,7 @@ class ExceptionHandler_Impl : public ExceptionHandler {
9395
private:
9496
Handler_t handler;
9597
};
96-
98+
9799
} // namespace GUIExceptionHandling
98100

99-
#endif /* GUI_Error_Handling_Impl_h */
101+
#endif /* GUI_Exception_Handling_Impl_h */

0 commit comments

Comments
 (0)