I have a macro in the catch section of code, say
#define CATCH( doSomething ) \
catch (MyException& e) \
{ \
try \
{ \
doSomething; \
} \
} \
catch (MyException* e) \
{ \
try \
{ \
doSomething; \
} \
}
and in the doSomething section I need to get to the contents of an exception, is there a way to do this? Some function isPointer that can be used like this:
try
{
THROW(new MyException());
}
CATCH( \
if( isPointer(e) ) \
{ \
std::cout << (*e).toString(); \
} \
else \
{ \
std::cout << e.toString(); \
} \
)
Just use overloading to possibly dereference the argument:
template<class T>
T& deref(T* p) { return *p; }
template<class T>
T& deref(T& r) { return r; }
And use that:
CATCH( \
std::cout << deref(e).toString(); \
)
Though I have to admit I see no reason to dynamically allocate exception objects.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With