dascandy / hippomocks

GNU Lesser General Public License v2.1
196 stars 67 forks source link

Compile error : cannot use 'throw' with exception disabled #59

Closed Europar closed 8 years ago

Europar commented 8 years ago

We get this compile error on ExceptionWrapper:rethrow() function in an environment where exceptions are disabled.

Enclosing the following code with #ifndef HM_NO_EXCEPTIONS solves the issue, not sure if this is something that can be taken back?

#ifndef HM_NO_EXCEPTIONS
//Type-safe exception wrapping
class ExceptionHolder
{
public:
    virtual ~ExceptionHolder() {}
    virtual void rethrow() = 0;
    template <typename T>
    static ExceptionHolder *Create(T ex);
};

template <class T>
class ExceptionWrapper : public ExceptionHolder {
    T exception;
public:
    ExceptionWrapper(T ex) : exception(ex) {}
    void rethrow() { throw exception; }
};

template <typename T>
ExceptionHolder *ExceptionHolder::Create(T ex)
{
    return new ExceptionWrapper<T>(ex);
}
#endif

Thanks!

dascandy commented 8 years ago

Looks fine to me. Can you put that in a pull request?

Also, what compiler do you use? Normally it would not instantiate the template until used, and of course it's not used. I think that's part of why it was not found so far.

dascandy commented 8 years ago

Fixed on c++11 branch. That one also has more features for when you have exceptions turned off - specifically, you can implement your own reporter that handles a failure in some way. One option is to throw an exception when something fails, but another option is to just get back to the test framework and continue with the next test. A third one could be to fork a new process for the remaining tests from the same executable and stop this instance. No obvious solutions though...

dascandy commented 8 years ago

Please reopen if it does not work for you.