#include "common-exceptions.h"
#include <forward_list>
-const struct gdb_exception exception_none;
-
/* Possible catcher states. */
enum catcher_state {
/* Initial state, a new catcher has just been created. */
/* Jump buffer pointing back at the exception handler. */
jmp_buf buf;
/* Status buffer belonging to the exception handler. */
- struct gdb_exception exception = exception_none;
+ struct gdb_exception exception;
};
/* Where to go for throw_exception(). */
/* Return EXCEPTION to the nearest containing CATCH_SJLJ block. */
void
-throw_exception_sjlj (struct gdb_exception exception)
+throw_exception_sjlj (const struct gdb_exception &exception)
{
/* Jump to the nearest CATCH_SJLJ block, communicating REASON to
that call via setjmp's return value. Note that REASON can't be
zero, by definition in common-exceptions.h. */
exceptions_state_mc (CATCH_THROWING);
+ enum return_reason reason = exception.reason;
catchers.front ().exception = exception;
- longjmp (catchers.front ().buf, exception.reason);
+ longjmp (catchers.front ().buf, reason);
}
/* Implementation of throw_exception that uses C++ try/catch. */
-static ATTRIBUTE_NORETURN void
-throw_exception_cxx (struct gdb_exception exception)
+void
+throw_exception (gdb_exception &&exception)
{
if (exception.reason == RETURN_QUIT)
- {
- gdb_exception_quit ex (exception);
- throw ex;
- }
+ throw gdb_exception_quit (std::move (exception));
else if (exception.reason == RETURN_ERROR)
- {
- gdb_exception_error ex (exception);
- throw ex;
- }
+ throw gdb_exception_error (std::move (exception));
else
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)
+ throw gdb_exception_quit (fmt, ap);
+ else if (reason == RETURN_ERROR)
+ throw gdb_exception_error (error, fmt, ap);
+ else
+ gdb_assert_not_reached ("invalid return reason");
}
void