[RFC,2/5,gdbsupport] Add CATCH_ERROR and CATCH_ERROR_QUIT
Commit Message
Add convenience macros CATCH_ERROR and CATCH_ERROR_QUIT, that can be used to
rewrite catch clauses of try/catch statements.
More concretely, this:
...
catch (const gdb_exception &VAR)
{
BODY;
}
...
into:
...
CATCH_ERROR_QUIT (VAR, {
BODY;
}
...
and this:
...
catch (const gdb_exception_error &VAR)
{
BODY;
}
...
into:
...
CATCH_ERROR (VAR, {
BODY;
}
...
---
gdbsupport/common-exceptions.h | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
@@ -294,6 +294,37 @@ struct gdb_exception_quit : public gdb_exception
}
};
+#define CATCH_ERROR_QUIT(VAR, BODY) \
+ catch (const gdb_exception_error &VAR) \
+ { \
+ BODY; \
+ } \
+ catch (const gdb_exception_quit &VAR) \
+ { \
+ BODY; \
+ } \
+ catch (const gdb_exception &) \
+ { \
+ /* Exception slicing occurred. */ \
+ gdb_assert (0); \
+ }
+
+#define CATCH_ERROR(VAR, BODY) \
+ catch (const gdb_exception_error &VAR) \
+ { \
+ BODY; \
+ } \
+ catch (const gdb_exception_quit &) \
+ { \
+ throw; \
+ } \
+ catch (const gdb_exception &) \
+ { \
+ /* Exception slicing occurred. */ \
+ gdb_assert (0); \
+ }
+
+
/* An exception type that inherits from both std::bad_alloc and a gdb
exception. This is necessary because operator new can only throw
std::bad_alloc, and OTOH, we want exceptions thrown due to memory