[Box Backup-commit] COMMIT r2544 - box/trunk/lib/common

boxbackup-dev@boxbackup.org boxbackup-dev@boxbackup.org
Sun, 5 Jul 2009 22:45:35 +0100 (BST)


Author: chris
Date: 2009-07-05 22:45:35 +0100 (Sun, 05 Jul 2009)
New Revision: 2544

Modified:
   box/trunk/lib/common/Box.h
   box/trunk/lib/common/Logging.h
   box/trunk/lib/common/Test.h
Log:
Suppress exception warnings when they are expected during a test.


Modified: box/trunk/lib/common/Box.h
===================================================================
--- box/trunk/lib/common/Box.h	2009-07-05 21:43:57 UTC (rev 2543)
+++ box/trunk/lib/common/Box.h	2009-07-05 21:45:35 UTC (rev 2544)
@@ -103,18 +103,25 @@
 
 #define THROW_EXCEPTION(type, subtype) \
 	{ \
-		OPTIONAL_DO_BACKTRACE \
-		BOX_WARNING("Exception thrown: " #type "(" #subtype ") " \
-			"at " __FILE__ "(" << __LINE__ << ")") \
+		if(!HideExceptionMessageGuard::ExceptionsHidden()) \
+		{ \
+			OPTIONAL_DO_BACKTRACE \
+			BOX_WARNING("Exception thrown: " \
+				#type "(" #subtype ") " \
+				"at " __FILE__ "(" << __LINE__ << ")") \
+		} \
 		throw type(type::subtype); \
 	}
 
 #define THROW_EXCEPTION_MESSAGE(type, subtype, message) \
 	{ \
-		OPTIONAL_DO_BACKTRACE \
-		BOX_WARNING("Exception thrown: " #type "(" #subtype ") " \
-			" (" message ") at " \
-			__FILE__ "(" << __LINE__ << ")") \
+		if(!HideExceptionMessageGuard::ExceptionsHidden()) \
+		{ \
+			OPTIONAL_DO_BACKTRACE \
+			BOX_WARNING("Exception thrown: " \
+				#type "(" #subtype ") (" message ") at " \
+				__FILE__ "(" << __LINE__ << ")") \
+		} \
 		throw type(type::subtype, message); \
 	}
 

Modified: box/trunk/lib/common/Logging.h
===================================================================
--- box/trunk/lib/common/Logging.h	2009-07-05 21:43:57 UTC (rev 2543)
+++ box/trunk/lib/common/Logging.h	2009-07-05 21:45:35 UTC (rev 2544)
@@ -320,4 +320,23 @@
 	virtual void SetProgramName(const std::string& rProgramName) { }
 };
 
+class HideExceptionMessageGuard
+{
+	public:
+	HideExceptionMessageGuard()
+	{
+		mOldHiddenState = sHiddenState;
+		sHiddenState = true;
+	}
+	~HideExceptionMessageGuard()
+	{
+		sHiddenState = mOldHiddenState;
+	}
+	static bool ExceptionsHidden() { return sHiddenState; }
+
+	private:
+	static bool sHiddenState;
+	bool mOldHiddenState;
+};
+
 #endif // LOGGING__H

Modified: box/trunk/lib/common/Test.h
===================================================================
--- box/trunk/lib/common/Test.h	2009-07-05 21:43:57 UTC (rev 2543)
+++ box/trunk/lib/common/Test.h	2009-07-05 21:45:35 UTC (rev 2544)
@@ -54,6 +54,7 @@
 #define TEST_CHECK_THROWS(statement, excepttype, subtype)									\
 	{																						\
 		bool didthrow = false;																\
+		HideExceptionMessageGuard hide; \
 		try																					\
 		{																					\
 			statement;																		\