Boost logo

Boost :

Subject: Re: [boost] Any interest in trap_exceptions functionality?
From: Andy Venikov (avenikov_at_[hidden])
Date: 2010-08-02 13:39:30

Stewart, Robert wrote:


> The idea is interesting, but I see issues of general applicability. For example, there are relatively few circumstances in which one needs to do much of that sort of exception handling. I don't mean to suggest that it doesn't occur, but I wonder if it occurs often enough to warrant a Boost tool.

Elsethread David Abrahams pointed out that Boost.Python and Boost.Test
already have a similar functionality. So, it looks like there has
already been some interest. The difference though is that what's there
right now is all run-time based.

I also feel that I didn't expand enough on the functional-style
qualities of trap_exceptions().

Since functional style is not a prevalent style of programming in C++
(but I think it's going to become more and more popular), coming up with
a good example is hard. But one could imaging that a piece of software
could be broken down into components not as usual with imperative style,
but as a set of collections of functions. For example,

// #1
   //Do functionality1
   ....use args
   //Do functionality2
   ....use args
   //Do functionality3(args)
   ...use args

Represents and old do-it-all function, which with the advent of
modularism can be split into


Whereas in the functional approach, we could have the set of 3
functionalities as a collection:

fusion::vector<...> functionSet = {functionality1(), functionality2(),

And then have a single "driver" function that goes through this colleciton:

   fusion::for_each(functionSet, invoke_(args) );//This will invoke all
three functionalities
//Also note that the resulting object code will be exactly as in #1

This way there will be more reflection on the structure of the
application. It's easier to change the behavior of this kind of
software. Note, that runtime vs. static is irrelevant for this
discussion. It could be either std::vector<>, fusion::vector<> or
mpl::vector<>, depending on the design.

If you take it even further, then the core "driver" function will take
the function to invoke on every element of the list as an argument:

   fusion::for_each(functionSet, Func);

If we just want all of the functionalities to be executed sequentially,
we'd call


We could also execute them conditionally (i.e. only if every predecessor


And here how you'd finally use the trap_exceptions:

driverFunction(compose(invoke_(args), trap_exceptions(Ex1, Ex2, Ex3)));

This will go over the list of function and execute them unconditionally
while catching and handling exceptions Ex1, Ex2 and Ex3.


Boost list run by bdawes at, gregod at, cpdaniel at, john at