I'm writing some code that necessitates my caching an exception.
Please consider
int main()
{
std::exception_ptr ex;
bool b = ex;
}
This doesn't compile due to ex
not being convertible to a bool
type. My current workaround is to write
bool b = !!ex;
or even
bool b = ex ? true : false;
The first way is ugly, the second one a tautology surely. I'm starting to blame the compiler (MSVC2015). Two things:
-
Is there a better way of checking if
ex
has been set to an exception? -
(Related) Do I need to initialise
ex
in some way?
Aucun commentaire:
Enregistrer un commentaire