From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 0AF5F3857427 for ; Tue, 25 Oct 2022 11:19:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0AF5F3857427 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 1F3D41F8D9 for ; Tue, 25 Oct 2022 11:19:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1666696786; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m3Lqp19CFKF3QG5fTwclA/UIqirXLTSzsiXMmAhfhCc=; b=R3lyYq7W9UpOKHzzoBwh6/DxT2+iUxUb5KuMbwDjADFAoYTqUEWxrEwm7ctB2EDGfqoPjq u7QCWjC0wG7+BJccQDy5gSAwiKb+XSiMhWabHs/0o4qEfL7zTn9lqcGNurQ7RNyKVevEyD x+Ib2NaUDjuc0QG/+fWvn4/uSFPiaP8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1666696786; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m3Lqp19CFKF3QG5fTwclA/UIqirXLTSzsiXMmAhfhCc=; b=4QqIgY0HNgXnTvxkJmTzp+9SV2gaQ5Ch9PqSuhq1uSVgow88C2NzGf3Hc8Zy60lkIj3ycM FBu22MMWB9mq+VAQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 0AF49134CA for ; Tue, 25 Oct 2022 11:19:46 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id qEl7AVLGV2O1dAAAMHmgww (envelope-from ) for ; Tue, 25 Oct 2022 11:19:46 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [RFC 2/5] [gdbsupport] Add CATCH_ERROR and CATCH_ERROR_QUIT Date: Tue, 25 Oct 2022 13:19:42 +0200 Message-Id: <20221025111945.23886-3-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221025111945.23886-1-tdevries@suse.de> References: <20221025111945.23886-1-tdevries@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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(+) diff --git a/gdbsupport/common-exceptions.h b/gdbsupport/common-exceptions.h index 543afda508a..ea998652edc 100644 --- a/gdbsupport/common-exceptions.h +++ b/gdbsupport/common-exceptions.h @@ -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 -- 2.35.3