Improve try_throw_exception

- fix comment
- clean up #ifdef organization based on PR feedback (agreed looks better)
This commit is contained in:
Jamie Seward 2017-10-24 23:25:11 -07:00
parent 0207d7e5fa
commit 4d349abb4d

View File

@ -501,24 +501,27 @@ class other_error : public exception
};
/*!
@brief helper function to throw the a downcasted exception.
@brief helper function to throw a downcasted exception.
*/
#ifdef JSON_EXCEPTIONS_ENABLED
template<class Exception>
void try_throw_exception(exception* ex)
{
#ifdef JSON_EXCEPTIONS_ENABLED
// Only use RTTI if necessary (exceptions are enabled). This way
// can be compiled with no RTTI.
// Only use RTTI if necessary (exceptions are enabled). This way
// can be compiled with no RTTI.
Exception* down = dynamic_cast<Exception*>(ex);
if(down != nullptr)
{
JSON_THROW(*down);
}
#else
ex = ex; // suppress unreferenced formal parameter warnings
std::abort();
#endif
}
#else
template<class Exception>
void try_throw_exception(exception* /*unused*/)
{
std::abort();
}
#endif
/*!
@brief helper function to throw the correct downcasted exception.