From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15207 invoked by alias); 19 Mar 2008 16:13:44 -0000 Received: (qmail 15197 invoked by uid 22791); 19 Mar 2008 16:13:44 -0000 X-Spam-Check-By: sourceware.org Received: from wa-out-1112.google.com (HELO wa-out-1112.google.com) (209.85.146.182) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 19 Mar 2008 16:13:21 +0000 Received: by wa-out-1112.google.com with SMTP id m16so450457waf.20 for ; Wed, 19 Mar 2008 09:13:19 -0700 (PDT) Received: by 10.114.126.1 with SMTP id y1mr1576106wac.108.1205943199726; Wed, 19 Mar 2008 09:13:19 -0700 (PDT) Received: by 10.114.120.5 with HTTP; Wed, 19 Mar 2008 09:13:19 -0700 (PDT) Message-ID: Date: Wed, 19 Mar 2008 16:13:00 -0000 From: "Jason Cipriani" To: gcc-help@gcc.gnu.org Subject: try, finally MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2008-03/txt/msg00176.txt.bz2 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