summaryrefslogtreecommitdiff
path: root/project2/structExceptHandling.cpp
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2011-07-28 23:58:39 +0000
committerrandomdan <randomdan@localhost>2011-07-28 23:58:39 +0000
commitc016b5d9d707c1be2b8ec1d48f8b1b3ddcdc6c9e (patch)
treee9aafb77e7094486af21acfb69ba7a6a0d132d05 /project2/structExceptHandling.cpp
parentPlugable variable doobries (diff)
downloadproject2-c016b5d9d707c1be2b8ec1d48f8b1b3ddcdc6c9e.tar.bz2
project2-c016b5d9d707c1be2b8ec1d48f8b1b3ddcdc6c9e.tar.xz
project2-c016b5d9d707c1be2b8ec1d48f8b1b3ddcdc6c9e.zip
Half decent error handling in scripts with project2:handler[try/catch/finally]
Component to validate a date string Merge some code (fixes sqlmerge missing attachments to ifs) Minor fixes New changelog importer in GB
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);
+}
+