Jonathan Wakely wrote:

> Do you mean like std::current_exception(), available in c++0x mode?

No, the main purpose of std::exception_ptr is to allow
passing exceptions between threads, but it is pretty
useless if it comes to reasoning about the exception
itself (i.e. it's not dereferencable). What I mean is the
exception value itself, for example:

   throw std::error("bug");

it will be a pointer to the std::error instance. But I was
partly wrong, the __cxa* functions are exported from
libstdc++, but in extern "C" mode. Now I have full access
to the __cxa_exception structure:

    struct __cxa_exception {

        std::type_info*             exceptionType;
        void (*exceptionDestructor) (void *);
        std::unexpected_handler     unexpectedHandler;
        std::terminate_handler      terminateHandler;
        __cxa_exception*            nextException;

        int                         handlerCount;
        int                         handlerSwitchValue;
        const char*                 actionRecord;
        const char*                 languageSpecificData;
        void*                       catchTemp;
        void*                       adjustedPtr;

        _Unwind_Exception           unwindHeader;
    };

But a question arises: may I assume that the adjustedPtr
field is always correctly filled by the compiler in contexts like this:

void remap_exception() {

    __cxa_eh_globals* const pEHGlobals = __cxa_get_globals();
    __cxa_exception* const pEHDescriptor = pEHGlobals->caughtExceptions;

    try {

        throw;

    } catch(...) {

            auto p = pEHDescriptor->adjustedPtr;

            // HERE
    }
}

?

The ABI specification says that __cxa_get_exception_ptr()
should be called in order to get the unwrapped object, but
when explicitly called, it returns null. On the other hand it
says that catches emit a call to this function together with
__cxa_begin_catch() and store the value in the current
__cxa_exception instance. So the answer to my question
should be "yes, the value of adjustedPtr is correct", but
it's better to ask in order to be sure.

    Best regards
    Piotr Wyderski

Reply via email to