
On Sun, Sep 19, 2010 at 08:59, Ulrich Eckhardt <doomster@knuut.de> wrote:
On Friday 17 September 2010 19:56:30 John Bytheway wrote:
[...]
That won't work in general; std::uncaught_exception might return true because of another pending exception that's going on 'outside' of foo() (e.g. if foo() is called from a destructor).
Thank you for the info about std::uncaught_exception. I've never actually used it. You could check the function in the constructor of the underlying C++
object, too, in order to detect transitions.
Checking in the constructor won't detect transitions. If foo() is called from a destructor during stack unwinding, then std::uncaught_exception() will return true twice, even if foo() terminated by yet another exception. Well, this could work if std::uncaught_exception had returned the number of pending exceptions. Could be a useful addition to the standard. On Sun, Sep 19, 2010 at 10:40, Martin Christiansson < martin.christiansson@gmail.com> wrote:
I've been thinking about a better solution. I need to call a lot of C-functions that use return value and errno for error reporting. Writing a lot of code around each call is a bit clumsy so I tried to create a guard macro instead that puts all relevant data into an exception if the "C function" returned an error.
If you're to make it a library, it's better to generalize for other APIs. E.g. use GetLastError() instead of errno for Windows API. #define RETVALGUARD(COND, FUNC, ...)
\ conditional_throw_legacy_exception(COND, \ boost::bind(FUNC, __VA_ARGS__)(), \ static_cast<const char*>(__FILE__), \ __LINE__, \ static_cast<const char*>(# FUNC))
Excuse me if I'm wrong again, but why use boost::bind? Why (FUNC)(__VA_ARGS__) won't work?