From 4d349abb4d8e5a89f1b1c15211b438c0a3d0a473 Mon Sep 17 00:00:00 2001 From: Jamie Seward Date: Tue, 24 Oct 2017 23:25:11 -0700 Subject: [PATCH] Improve try_throw_exception - fix comment - clean up #ifdef organization based on PR feedback (agreed looks better) --- src/json.hpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/json.hpp b/src/json.hpp index 02a4a2620..2c9c2c00e 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -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 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(ex); if(down != nullptr) { JSON_THROW(*down); } -#else - ex = ex; // suppress unreferenced formal parameter warnings - std::abort(); -#endif } +#else +template +void try_throw_exception(exception* /*unused*/) +{ + std::abort(); +} +#endif /*! @brief helper function to throw the correct downcasted exception.