aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2013-06-03 12:20:52 +0200
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2014-02-15 18:38:24 +0100
commit707acef9b3b83a1ecf945a40e14d83cce947b766 (patch)
treee4501baa2cfb1e4d380da034df32ad407b2c4478
parent8046e11445ba71b767d4fde08ce1e43e0dcd0359 (diff)
downloadsciteco-707acef9b3b83a1ecf945a40e14d83cce947b766.tar.gz
added State::StdError class for constructing errors from std::exception objects
-rw-r--r--src/main.cpp2
-rw-r--r--src/parser.cpp12
-rw-r--r--src/parser.h11
3 files changed, 19 insertions, 6 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 974aed2..01e2594 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -24,7 +24,7 @@
#include <string.h>
#include <stdlib.h>
#include <signal.h>
-#include <stdexcept>
+#include <new>
#include <glib.h>
#include <glib/gprintf.h>
diff --git a/src/parser.cpp b/src/parser.cpp
index aed9348..0347146 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -21,7 +21,7 @@
#include <stdarg.h>
#include <string.h>
-#include <stdexcept>
+#include <exception>
#include <glib.h>
#include <glib/gprintf.h>
@@ -88,15 +88,17 @@ Execute::step(const gchar *macro, gint stop_pos)
#endif
try {
- /* convert bad_alloc exceptions */
+ /*
+ * convert bad_alloc and other C++ standard
+ * library exceptions
+ */
try {
if (interface.is_interrupted())
throw State::Error("Interrupted");
State::input(macro[macro_pc]);
- } catch (std::bad_alloc &alloc) {
- throw State::Error("bad_alloc: %s",
- alloc.what());
+ } catch (std::exception &error) {
+ throw State::StdError(error);
}
} catch (State::Error &error) {
error.pos = macro_pc;
diff --git a/src/parser.h b/src/parser.h
index 8e73d64..f29ea38 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -18,6 +18,9 @@
#ifndef __PARSER_H
#define __PARSER_H
+#include <exception>
+#include <typeinfo>
+
#include <glib.h>
#include <glib/gprintf.h>
@@ -156,6 +159,14 @@ public:
void display_full(void);
};
+ class StdError : public Error {
+ public:
+ StdError(const gchar *type, const std::exception &error)
+ : Error("%s: %s", type, error.what()) {}
+ StdError(const std::exception &error)
+ : Error("%s: %s", typeid(error).name(), error.what()) {}
+ };
+
class GError : public Error {
public:
GError(const ::GError *gerror)