Boost logo

Boost :

From: davidbien_at_[hidden]
Date: 2000-04-17 14:56:46


I have some throw-safety testing objects, that I have found useful in
debugging my own code wrt throw-safety.

The usage is as follows:

#include "_dbgthrw.h"

At each point in the code that could potentially throw ( sounds like
a lot of work, eh ? :-) place a statement:

__THROWPT( type )

where type is one of ( currently ):
{ e_ttMemory, e_ttFileOutput, e_ttFileInput }

then to enable debug throwing, don't define __NDEBUG_THROW, and
somewhere ( likely in main() ) set the random seed, the throw rate,
and turn on throwing debugging:

  _throw_object_base::ms_tsb.set_seed( uRandSeed );
  _throw_object_base::ms_tsb.set_throw_rate( iThrowRate );
  _throw_object_base::ms_tsb.set_on( true );

then each time a throw point is passed, it randomly may throw.

A record of throw-points passed is maintained, and it is recorded how
many possible times that point could have thrown, and how many times
it did. The un-thrown-from throw points can be dumped to an ostream.
This information can be used to create a "special throwing schedule"
for "hard to throw from" throw-points - i.e. throw-points that are
hit only once or twice in the course of an execution. This array (
likely set in in main ) is of the form:

const int kiNSpecialTP = 10;
_throw_object_with_throw_rate rgtobtrSpecial[kiNSpecial];
                        
rgtobtrSpecial[9].m_cpFileName = "C:\\dv\\dslib\\_gr_stin.h";
rgtobtrSpecial[9].m_ulLineNumber = 105;
rgtobtrSpecial[9].m_iThrowRate = 4;
rgtobtrSpecial[9].m_fHitOnce = false;

when a throw-point is encountered, this schedule is searched, and the
special throw rate is used if one is found.

The system seemed to work well for me. It gives more confidence in
the throw-safety of code ( since bugs are found :-)

David Bien


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk