From: "Jason Cipriani" <jason.cipriani@gmail.com>
To: gcc-help@gcc.gnu.org
Subject: try, finally
Date: Wed, 19 Mar 2008 16:13:00 -0000 [thread overview]
Message-ID: <c09049bf0803190913p220b33dif24d4862d878801d@mail.gmail.com> (raw)
Does GCC have anything similar to the MS and Borland compiler's __try
and __finally keywords? When using GCC I often find that I have code
like this (a moderately complex, and highly contrived, example):
====
void *data1 = NULL, *data2 = NULL, *data3 = NULL;
try {
if (!(data1 = malloc(1000)))
throw Something();
if (!(data2 = malloc(1000)))
throw Something();
if (!(data3 = malloc(1000)))
throw Something();
} catch (...) {
// cleanup code
free(data3);
free(data2);
free(data1);
throw;
}
// the same cleanup code
free(data3);
free(data2);
free(data1);
===
Where I am duplicating cleanup code for normal returns and exception
handling, but what I really want to do is something like this:
===
void *data1 = NULL, *data2 = NULL, *data3 = NULL;
__try {
if (!(data1 = malloc(1000)))
throw Something();
if (!(data2 = malloc(1000)))
throw Something();
if (!(data3 = malloc(1000)))
throw Something();
// do stuff
} __finally {
// cleanup code
free(data3);
free(data2);
free(data1);
}
===
Thanks,
Jason
next reply other threads:[~2008-03-19 16:13 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-19 16:13 Jason Cipriani [this message]
2008-03-19 16:14 ` Jason Cipriani
2008-03-19 17:02 ` Tim Prince
2008-03-19 16:37 ` Brian Dessent
2008-03-19 17:31 ` Ted Byers
2008-03-19 17:37 ` me22
2008-03-19 19:09 ` Jason Cipriani
2008-03-19 19:09 ` me22
2008-03-20 5:50 ` Jason Cipriani
2008-03-20 13:30 ` Noel Yap
2008-03-21 2:27 ` Jason Cipriani
2008-03-19 21:04 ` Ted Byers
2008-03-20 6:28 ` Jason Cipriani
2008-03-20 12:24 ` John Love-Jensen
2008-03-21 2:11 ` Jason Cipriani
2008-03-21 2:37 ` me22
2008-03-21 2:45 ` Jason Cipriani
2008-03-21 15:24 ` Noel Yap
2008-03-21 22:50 ` Brian Dessent
2008-03-21 23:14 ` Noel Yap
2008-03-20 14:50 ` Ted Byers
2008-03-21 2:26 ` Jason Cipriani
2008-03-25 22:28 ` Ian Lance Taylor
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c09049bf0803190913p220b33dif24d4862d878801d@mail.gmail.com \
--to=jason.cipriani@gmail.com \
--cc=gcc-help@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).