summaryrefslogtreecommitdiff
path: root/project2/structExceptHandling.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'project2/structExceptHandling.cpp')
-rw-r--r--project2/structExceptHandling.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/project2/structExceptHandling.cpp b/project2/structExceptHandling.cpp
new file mode 100644
index 0000000..f87b870
--- /dev/null
+++ b/project2/structExceptHandling.cpp
@@ -0,0 +1,53 @@
+#include "structExceptHandling.h"
+#include "xmlObjectLoader.h"
+#include "xmlStorage.h"
+#include <boost/foreach.hpp>
+
+DECLARE_LOADER("handler", StructuredExceptionHandler);
+
+static void
+loadHelper(const char * name, const xmlpp::Element * root, ANONORDEREDSTORAGEOF(NoOutputExecute) * noes)
+{
+ LoaderBase loader(true);
+ loader.supportedStorers.insert(Storer::into(noes));
+ BOOST_FOREACH(const xmlpp::Node * node, root->find(name)) {
+ const xmlpp::Element * elem = dynamic_cast<const xmlpp::Element *>(node);
+ if (elem) {
+ loader.collectAll(elem, true, ErrorOnUnsupported);
+ }
+ }
+}
+
+StructuredExceptionHandler::StructuredExceptionHandler(const xmlpp::Element * e) :
+ SourceObject(e),
+ IHaveSubTasks(e)
+{
+ loadHelper("try", e, &normal);
+ loadHelper("catch", e, &catches);
+ loadHelper("finally", e, &finallies);
+}
+
+void
+StructuredExceptionHandler::loadComplete(const CommonObjects * co)
+{
+ IHaveSubTasks::loadComplete(co);
+}
+
+void
+StructuredExceptionHandler::execute() const
+{
+ try {
+ run(normal);
+ }
+ catch (...) {
+ try {
+ run(catches);
+ }
+ catch (...) {
+ }
+ run(finallies);
+ throw;
+ }
+ run(finallies);
+}
+