From 707acef9b3b83a1ecf945a40e14d83cce947b766 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Mon, 3 Jun 2013 12:20:52 +0200 Subject: added State::StdError class for constructing errors from std::exception objects --- src/main.cpp | 2 +- src/parser.cpp | 12 +++++++----- src/parser.h | 11 +++++++++++ 3 files changed, 19 insertions(+), 6 deletions(-) (limited to 'src') 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 #include #include -#include +#include #include #include 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 #include -#include +#include #include #include @@ -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 +#include + #include #include @@ -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) -- cgit v1.2.3