A
avasilev
Hi all
Its one of my little pragramming challenges to implement a try/finally
construct in C++. I have done several implementations but they all have
limitations. Have tried mostly using a destructor to execute the
"finally" code. However this has the big limitation that the destructor
cannot see local variables. Another approach that solves this problem
is the following:
{
MyBaseException* handledException = NULL;
try
{
<try code>
}
catch(MyBaseException& e)
{
handledException = e.Clone();
}
<finally code>
if (handledException)
throw *handledException;
}
However, this method has the limitation that it works only for specific
classes of exception objects.
I'm curious to see other ideas
Regards
Alex
Its one of my little pragramming challenges to implement a try/finally
construct in C++. I have done several implementations but they all have
limitations. Have tried mostly using a destructor to execute the
"finally" code. However this has the big limitation that the destructor
cannot see local variables. Another approach that solves this problem
is the following:
{
MyBaseException* handledException = NULL;
try
{
<try code>
}
catch(MyBaseException& e)
{
handledException = e.Clone();
}
<finally code>
if (handledException)
throw *handledException;
}
However, this method has the limitation that it works only for specific
classes of exception objects.
I'm curious to see other ideas
Regards
Alex