@@ -437,12 +437,27 @@ class DelegateFreeAsyncWait<RetType(Args...)> : public DelegateFree<RetType(Args
437437 // / Get the asynchronous function return value
438438 // / @return The destination thread target function return value
439439 RetType GetRetVal () noexcept {
440+ // Use pointer cast if exceptions are disabled OR if user requested Asserts-only mode
441+ #if !defined(__cpp_exceptions) || defined(DMQ_ASSERTS)
442+ // Fast, non-throwing check suitable for Embedded/Real-time
443+ auto * p = std::any_cast<RetType>(&m_retVal);
444+ if (p) return *p;
445+
446+ // Optional: If you want to trap this error in debug mode
447+ #if defined(DMQ_ASSERTS)
448+ ASSERT ();
449+ #endif
450+
451+ return RetType ();
452+ #else
453+ // Standard C++ behavior with Exception Handling
440454 try {
441455 return std::any_cast<RetType>(m_retVal);
442456 }
443457 catch (const std::bad_any_cast&) {
444- return RetType (); // Return a default value if error
458+ return RetType ();
445459 }
460+ #endif
446461 }
447462
448463 // /@brief Get the destination thread that the target function is invoked on.
@@ -858,12 +873,27 @@ class DelegateMemberAsyncWait<TClass, RetType(Args...)> : public DelegateMember<
858873 // / Get the asynchronous function return value
859874 // / @return The destination thread target function return value
860875 RetType GetRetVal () noexcept {
876+ // Use pointer cast if exceptions are disabled OR if user requested Asserts-only mode
877+ #if !defined(__cpp_exceptions) || defined(DMQ_ASSERTS)
878+ // Fast, non-throwing check suitable for Embedded/Real-time
879+ auto * p = std::any_cast<RetType>(&m_retVal);
880+ if (p) return *p;
881+
882+ // Optional: If you want to trap this error in debug mode
883+ #if defined(DMQ_ASSERTS)
884+ ASSERT ();
885+ #endif
886+
887+ return RetType ();
888+ #else
889+ // Standard C++ behavior with Exception Handling
861890 try {
862891 return std::any_cast<RetType>(m_retVal);
863892 }
864893 catch (const std::bad_any_cast&) {
865- return RetType (); // Return a default value if error
894+ return RetType ();
866895 }
896+ #endif
867897 }
868898
869899 // /@brief Get the destination thread that the target function is invoked on.
@@ -1196,12 +1226,27 @@ class DelegateMemberAsyncWaitSp<TClass, RetType(Args...)> : public DelegateMembe
11961226 // / Get the asynchronous function return value
11971227 // / @return The destination thread target function return value
11981228 RetType GetRetVal () noexcept {
1229+ // Use pointer cast if exceptions are disabled OR if user requested Asserts-only mode
1230+ #if !defined(__cpp_exceptions) || defined(DMQ_ASSERTS)
1231+ // Fast, non-throwing check suitable for Embedded/Real-time
1232+ auto * p = std::any_cast<RetType>(&m_retVal);
1233+ if (p) return *p;
1234+
1235+ // Optional: If you want to trap this error in debug mode
1236+ #if defined(DMQ_ASSERTS)
1237+ ASSERT ();
1238+ #endif
1239+
1240+ return RetType ();
1241+ #else
1242+ // Standard C++ behavior with Exception Handling
11991243 try {
12001244 return std::any_cast<RetType>(m_retVal);
12011245 }
12021246 catch (const std::bad_any_cast&) {
1203- return RetType (); // Return a default value if error
1247+ return RetType ();
12041248 }
1249+ #endif
12051250 }
12061251
12071252 // /@brief Get the destination thread that the target function is invoked on.
@@ -1536,12 +1581,27 @@ class DelegateFunctionAsyncWait<RetType(Args...)> : public DelegateFunction<RetT
15361581 // / Get the asynchronous function return value
15371582 // / @return The destination thread target function return value
15381583 RetType GetRetVal () noexcept {
1584+ // Use pointer cast if exceptions are disabled OR if user requested Asserts-only mode
1585+ #if !defined(__cpp_exceptions) || defined(DMQ_ASSERTS)
1586+ // Fast, non-throwing check suitable for Embedded/Real-time
1587+ auto * p = std::any_cast<RetType>(&m_retVal);
1588+ if (p) return *p;
1589+
1590+ // Optional: If you want to trap this error in debug mode
1591+ #if defined(DMQ_ASSERTS)
1592+ ASSERT ();
1593+ #endif
1594+
1595+ return RetType ();
1596+ #else
1597+ // Standard C++ behavior with Exception Handling
15391598 try {
15401599 return std::any_cast<RetType>(m_retVal);
15411600 }
15421601 catch (const std::bad_any_cast&) {
1543- return RetType (); // Return a default value if error
1602+ return RetType ();
15441603 }
1604+ #endif
15451605 }
15461606
15471607 // /@brief Get the destination thread that the target function is invoked on.
0 commit comments