Re: Proposal: A block between "try" and "catch".
On 6 Jun., 06:22, "Adam H. Peterson" <alpha.eta...@gmail.com> wrote:
On Jun 5, 4:55 pm, peter koch larsen <peter.koch.lar...@gmail.com>
wrote:
What is wrong with:
[snip wrong solution]
This handles exactly what you want to handle.
Actually, it handles exactly the opposite of what I want to handle.
The exception from the construction of ob will propagate, and the
exception from do_something_else will not.
Of course, I misread your original post. No wonder I was slightly
surprised by your question. Morale: never post when you're tired.
I believe this is obfuscation. A catch block that sometimes does not
catch anything is not something I would recommend.
Most catch blocks sometimes don't catch anything -- if that exception
isn't thrown, or is thrown outside the try block. And in a more
direct parallel, a catch block won't catch something that's thrown
within another catch block (even an earlier catch block for the same
try block). That was the semantic I was trying to parallel. But, I'm
not married to the syntax. I'm just looking for some solution to the
expression of the problem.
I still don't like your syntax. Probably you already tried something
like:
try {
bool ob_created(false);
Object ob("data"); // May throw range_error
ob_created = true;
// This may also throw range_error,
// but I don't want to catch this one
do_something_else(ob, "other data");
} catch (range_error e) {
if (ob_created)
throw;
// handle the failed construction of ob.
}
It is not to elegant, but does the job. If the above gets to tiresome,
perhaps Barbatis boost::optional proposal is better?
/Peter
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]