D
Douglas Peterson
I have a simple class that verifies some data between the beginning and the
end of a function:
class Verify
{
Verify() { note the data value }
~Verify() { check if data value is the same as we noted }
};
void foo()
{
Verify _v;
...
throw SomeException; // test can fail because _v is destroyed
'prematurely'
...
};
~Verify() just makes an assertion to warn me that I've done something wrong
in the function body.
If the exception occurs, the verification is no longer relevant.
Is there some way to detect that I'm (~Verify()) being destroyed by an
exception rather than the end of scope?
i.e.
~Verify()
{ if (!exception) assert(...); }
I know I could add another variable into the function, or set some member of
Verify before I throw, but that defeats the point of using the Verify class
as a simple way to test the integrity of the function.
end of a function:
class Verify
{
Verify() { note the data value }
~Verify() { check if data value is the same as we noted }
};
void foo()
{
Verify _v;
...
throw SomeException; // test can fail because _v is destroyed
'prematurely'
...
};
~Verify() just makes an assertion to warn me that I've done something wrong
in the function body.
If the exception occurs, the verification is no longer relevant.
Is there some way to detect that I'm (~Verify()) being destroyed by an
exception rather than the end of scope?
i.e.
~Verify()
{ if (!exception) assert(...); }
I know I could add another variable into the function, or set some member of
Verify before I throw, but that defeats the point of using the Verify class
as a simple way to test the integrity of the function.