S
Stefan Arentz
I was just reading through some old articles in the 'Why not develop new
language' thread and came across the finally debate.
Everytime I mention 'finally' to C++ programmers I get almost emotional
responses about why it is not needed in C++. I don't get that.
For example, consider the following code. Please note, I can only use
heap allocated objects in my current project (new/delete).
//
// Foo - Tries to foo. Can throw a FooException
//
void Foo()
{
try {
// Do your foo business that could throw a FooException
}
catch (...) {
// Cleanup your business
throw;
}
// Cleanup your business
}
Now, with finally I could do this:
void Foo()
{
try {
// Do your foo business that could throw a FooException
}
finally {
// Cleanup your business
}
}
Which I find *much* cleaner than the other example as there is no
need to do the cleanup twice.
Anyway, the debate is useless because we don't have finally. So my question
really is, how do people refactor the above to something nicer?
S.
language' thread and came across the finally debate.
Everytime I mention 'finally' to C++ programmers I get almost emotional
responses about why it is not needed in C++. I don't get that.
For example, consider the following code. Please note, I can only use
heap allocated objects in my current project (new/delete).
//
// Foo - Tries to foo. Can throw a FooException
//
void Foo()
{
try {
// Do your foo business that could throw a FooException
}
catch (...) {
// Cleanup your business
throw;
}
// Cleanup your business
}
Now, with finally I could do this:
void Foo()
{
try {
// Do your foo business that could throw a FooException
}
finally {
// Cleanup your business
}
}
Which I find *much* cleaner than the other example as there is no
need to do the cleanup twice.
Anyway, the debate is useless because we don't have finally. So my question
really is, how do people refactor the above to something nicer?
S.