+2019-04-08 Tom Tromey <tom@tromey.com>
+
+ * common/common-exceptions.c (throw_exception): Rename from
+ throw_exception_cxx. Remove old copy. Make argument const.
+ (throw_it): Create and throw exception objects directly.
+ * common/common-exceptions.h (throw_exception): Make argument
+ const.
+ (struct gdb_exception_error): Add constructor.
+ (struct gdb_exception_quit): Add constructor.
+
2019-04-08 Tom Tromey <tom@tromey.com>
* common/common-exceptions.h (exception_rethrow): Don't declare.
/* Implementation of throw_exception that uses C++ try/catch. */
-static ATTRIBUTE_NORETURN void
-throw_exception_cxx (struct gdb_exception exception)
+void
+throw_exception (const gdb_exception &exception)
{
if (exception.reason == RETURN_QUIT)
{
gdb_assert_not_reached ("invalid return reason");
}
-void
-throw_exception (struct gdb_exception exception)
-{
- throw_exception_cxx (exception);
-}
-
static void ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (3, 0)
throw_it (enum return_reason reason, enum errors error, const char *fmt,
va_list ap)
{
- struct gdb_exception e;
-
- /* Create the exception. */
- e.reason = reason;
- e.error = error;
- e.message.reset (new std::string (string_vprintf (fmt, ap)));
-
- /* Throw the exception. */
- throw_exception (e);
+ if (reason == RETURN_QUIT)
+ {
+ gdb_exception_quit ex (reason, error);
+ ex.message.reset (new std::string (string_vprintf (fmt, ap)));
+ throw ex;
+ }
+ else if (reason == RETURN_ERROR)
+ {
+ gdb_exception_error ex (reason, error);
+ ex.message.reset (new std::string (string_vprintf (fmt, ap)));
+ throw ex;
+ }
+ else
+ gdb_assert_not_reached ("invalid return reason");
}
void
struct gdb_exception_error : public gdb_exception
{
+ gdb_exception_error (enum return_reason r, enum errors e)
+ : gdb_exception (r, e)
+ {
+ }
+
explicit gdb_exception_error (const gdb_exception &ex) noexcept
: gdb_exception (ex)
{
struct gdb_exception_quit : public gdb_exception
{
+ gdb_exception_quit (enum return_reason r, enum errors e)
+ : gdb_exception (r, e)
+ {
+ }
+
explicit gdb_exception_quit (const gdb_exception &ex) noexcept
: gdb_exception (ex)
{
/* Throw an exception (as described by "struct gdb_exception"),
landing in the inner most containing exception handler established
using TRY/CATCH. */
-extern void throw_exception (struct gdb_exception exception)
+extern void throw_exception (const gdb_exception &exception)
ATTRIBUTE_NORETURN;
/* Throw an exception by executing a LONG JUMP to the inner most