diff --git a/include/nlohmann/detail/input/json_sax.hpp b/include/nlohmann/detail/input/json_sax.hpp
index ae6a6cbe..d4c32913 100644
--- a/include/nlohmann/detail/input/json_sax.hpp
+++ b/include/nlohmann/detail/input/json_sax.hpp
@@ -263,6 +263,7 @@ class json_sax_dom_parser
                      const Exception& ex)
     {
         errored = true;
+        (void)ex;
         if (allow_exceptions)
         {
             JSON_THROW(ex);
@@ -501,6 +502,7 @@ class json_sax_dom_callback_parser
                      const Exception& ex)
     {
         errored = true;
+        (void)ex;
         if (allow_exceptions)
         {
             JSON_THROW(ex);
diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp
index 0b7d2411..67beb73a 100644
--- a/single_include/nlohmann/json.hpp
+++ b/single_include/nlohmann/json.hpp
@@ -5441,6 +5441,7 @@ class json_sax_dom_parser
                      const Exception& ex)
     {
         errored = true;
+        (void)ex;
         if (allow_exceptions)
         {
             JSON_THROW(ex);
@@ -5679,6 +5680,7 @@ class json_sax_dom_callback_parser
                      const Exception& ex)
     {
         errored = true;
+        (void)ex;
         if (allow_exceptions)
         {
             JSON_THROW(ex);