Boost logo

Boost :

Subject: Re: [boost] D-style scope guards?
From: Martin Christiansson (martin.christiansson_at_[hidden])
Date: 2010-09-17 07:49:44


> Why don't you use std::uncaught_exception() instead of exception_thrown?
>

For a very simple reason. I've missed that one probably due to only
resorting to try-catch and Alexandrescu/Loki scopeguards.
Did not know that the method existed. Thanks for the tip!

> Anyway in real code using a commit variable directly reflects the intent
> better. Perhaps if I'm wrong, please give a real-world example when your
> scope guards are more appropriate.
>

The only benefit is that when you return an error code (without using
the return macro), unwind will happen as if an exception had been
thrown. This can of course be solved by means of defining and throwing
an exception instead of indicating error with negative return code
followed by an enclosing try-catch that translates to integer return
value. This is only useful when calling a bunch of C-functions that
will not, under any circumstances, throw exceptions. It will not add
any benefits compared to your example example in a pure C++ design.

/Martin


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