Re: Suggested extention of the break statement
Gerard J. Cerchio wrote:
First of all, try to in general use RAII (objects with proper
destructors,
handling clean-up in destructors) rather than try-catch.
And second, it seems that you're addressing the case of trying to do all
too much in one function, for which it's usually a better solution to
break that large function up into smaller, more focused functions.
That said,
// B
#define BEGIN_BREAKABLE for(;;){
#define END_BREAKABLE break;}
int bar()
{
int result = 1;
BEGIN_BREAKABLE
try
{
// Some code
break;
// More code
result = 2;
}
catch( ... ) { std::terminate(); }
END_BREAKABLE
return result;
}
I already suggested
#define BEGIN_BREAKABLE do {
#define END_BREAKABLE } while (false);
But that still allows a bogus continue statement.
What about:
#define BEGIN_BREAKABLE switch(0) { default:
#define END_BREAKABLE break; }
This prevents bogus continue statements.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]