From -4638001631789072400
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: f78e5,972722ed514d508a
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2001-07-30 03:33:00 PST
Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!dispose.news.demon.net!news.demon.co.uk!demon!mail2news.demon.co.uk!not-for-mail
From: "Anthony Williams" <anthwil@nortelnetworks.com>
Newsgroups: comp.std.c++
Subject: Re: try block as main block of a function
Date: Mon, 30 Jul 2001 10:32:35 GMT
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
Message-ID: <9k34ms$2akk5$1@ID-49767.news.dfncis.de>
References: <3b6061b5.1188820@news.terra.es> <cKmyuWA$AJY7EwG1@ntlworld.com> <9jr8bd$19vqd$1@ID-49767.news.dfncis.de> <OOB2fjAifdY7Ewle@ntlworld.com>
X-Trace: mail2news.demon.co.uk 996489160 mail2news:6180 mail2news mail2news.demon.co.uk
X-Complaints-To: abuse@demon.net
X-Mail2News-Path: news.demon.net!mulga.cs.mu.oz.au
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Orig-NNTP-Posting-Host: 47.160.2.96
X-Orig-X-Trace: fu-berlin.de 996480540 2445957 47.160.2.96 (16 [49767])
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4522.1200
X-MIMEOLE: Produced By Microsoft MimeOLE V5.50.4522.1200
Lines: 41
Xref: archiver1.google.com comp.std.c++:6813

"Francis Glassborow" <francis.glassborow@ntlworld.com> wrote in message
news:OOB2fjAifdY7Ewle@ntlworld.com...
> In article <9jr8bd$19vqd$1@ID-49767.news.dfncis.de>, Anthony Williams
> <anthwil@nortelnetworks.com> writes
> >Why would you not advocate using function try blocks?
>
> Because many will forget that they automatically rethrow if you do not
> do so. I hate default behaviour as it often hides errors.

8.4p16 says:
"The exception being handled is rethrown if control reaches the end of a
handler of the function-try-block of a constructor or destructor. Otherwise,
a function returns when control reaches the end of a handler for the
function-try-block (6.6.3). Flowing off the end of a function-try-block is
equivalent to a return with no value; this results in undefined behavior in
a value-returning function (6.6.3)."

Thus it seems that function try blocks only have this behaviour in
constructors and destructors. I'll go with not recommending them for
destructors, but their use with constructors is the reason they were
introduced in the first place (as you said in your original reply). For
functions it saves a level of indentation and a pair of braces, but
otherwise is identical to a function body containing nothing but a try
block. The only reason I can see for not recommending it is portability
(e.g.Daniel Garc�a's original problem wrt MSVC).

Anthony
--
Anthony Williams
Software Engineer, Nortel Networks Optoelectronics
The opinions expressed in this message are not necessarily those of my
employer



---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]



