summaryrefslogtreecommitdiff
path: root/include/cppunit/Exception.h
diff options
context:
space:
mode:
authorBaptiste Lepilleur <gaiacrtn@free.fr>2002-06-13 14:31:01 +0000
committerBaptiste Lepilleur <gaiacrtn@free.fr>2002-06-13 14:31:01 +0000
commitabd178318ae3cdb6cc0a700e77414a33ef9297ca (patch)
tree76bb1f6d0bf28bfe23c710487d0b20bd95878ca4 /include/cppunit/Exception.h
parent3702f4f7603f1e49b4d6747c49e795bad712eab7 (diff)
downloadcppunit-abd178318ae3cdb6cc0a700e77414a33ef9297ca.tar.gz
Include/cppunit/Asserter.
include/cppunit/Asserter.h: * src/cppunit/Asserter.cpp: added functions that take a Message as a parameter. Existing function have a short description indicating an assertion failure. * include/cppunit/CompilerOuputter.h: * src/cppunit/CompilerOuputter.cpp: removed printNotEqualMessage() and printDefaultMessage(). Updated to use Message. * include/cppunit/Message.h: * src/cppunit/Message.cpp: added. Represents a message associated to an Exception. * include/cppunit/Exception.h: * src/cppunit/Exception.cpp: the message associated to the exception is now stored as a Message instead of a string. * include/cppunit/NotEqualException.cpp: constructs a Message instead of a string. * include/cppunit/TestAssert.h: * src/cppunit/TestAssert.cpp: updated to use Asserter functions that take a message when pertinent (CPPUNIT_FAIL...). * include/cppunit/TestCaller.h: * src/cppunit/TestCaller.cpp: exception not caught failure has a better short description. * src/cppunit/TestCase.cpp: better short description when setUp() or tearDown() fail. * src/msvc6/testrunner/TestRunnerDlg.cpp: replace '\n' in failure message with space. * examples/cppunittest/ExceptionTest.cpp: * examples/cppunittest/NotEqualExceptionTest.cpp: * examples/cppunittest/TestCallerTest.cpp: * examples/cppunittest/TestFailureTest.cpp: * examples/cppunittest/TestResultCollectorTest.h: * examples/cppunittest/TestResultCollectorTest.cpp: * examples/cppunittest/TestResultTest.cpp: * examples/cppunittest/XmlOutputterTest.h: * examples/cppunittest/XmlOutputterTest.cpp: updated to use Exception/Message. * examples/cppunittest/MessageTest.h: * examples/cppunittest/MessageTest.cpp: added. Unit test for Message.
Diffstat (limited to 'include/cppunit/Exception.h')
-rw-r--r--include/cppunit/Exception.h98
1 files changed, 63 insertions, 35 deletions
diff --git a/include/cppunit/Exception.h b/include/cppunit/Exception.h
index 505d16e..afadd00 100644
--- a/include/cppunit/Exception.h
+++ b/include/cppunit/Exception.h
@@ -2,9 +2,10 @@
#define CPPUNIT_EXCEPTION_H
#include <cppunit/Portability.h>
+#include <cppunit/Message.h>
#include <cppunit/SourceLine.h>
#include <exception>
-#include <string>
+
namespace CppUnit {
@@ -18,60 +19,87 @@ class CPPUNIT_API Exception : public std::exception
{
public:
- class Type
+ class Type
+ {
+ public:
+ Type( std::string type ) : m_type ( type )
+ {
+ }
+
+ bool operator ==( const Type &other ) const
{
- public:
- Type( std::string type ) : m_type ( type ) {}
+ return m_type == other.m_type;
+ }
- bool operator ==( const Type &other ) const
- {
- return m_type == other.m_type;
- }
- private:
- const std::string m_type;
- };
+ private:
+ const std::string m_type;
+ };
- Exception( std::string message = "",
- SourceLine sourceLine = SourceLine() );
+ /*! Constructs the exception with the specified message and source location.
+ * \param message Message associated to the exception.
+ * \param sourceLine Source location related to the exception.
+ */
+ Exception( const Message &message = Message(),
+ const SourceLine &sourceLine = SourceLine() );
#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED
- Exception( std::string message,
- long lineNumber,
- std::string fileName );
+ /*!
+ * \deprecated Use other constructor instead.
+ */
+ Exception( std::string message,
+ long lineNumber,
+ std::string fileName );
#endif
- Exception (const Exception& other);
+ /*! Constructs a copy of an exception.
+ * \param other Exception to copy.
+ */
+ Exception( const Exception &other );
- virtual ~Exception () throw();
+ /// Destructs the exception
+ virtual ~Exception() throw();
- Exception& operator= (const Exception& other);
+ /// Performs an assignment
+ Exception &operator =( const Exception &other );
- const char *what() const throw ();
+ /// Returns descriptive message
+ const char *what() const throw();
- SourceLine sourceLine() const;
+ /// Location where the error occured
+ SourceLine sourceLine() const;
+
+ /// Message related to the exception.
+ Message message() const;
#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED
- long lineNumber() const;
- std::string fileName() const;
+ /// The line on which the error occurred
+ long lineNumber() const;
+
+ /// The file in which the error occurred
+ std::string fileName() const;
- static const std::string UNKNOWNFILENAME;
- static const long UNKNOWNLINENUMBER;
+ static const std::string UNKNOWNFILENAME;
+ static const long UNKNOWNLINENUMBER;
#endif
- virtual Exception *clone() const;
-
- virtual bool isInstanceOf( const Type &type ) const;
+ /// Clones the exception.
+ virtual Exception *clone() const;
+
+ /// Tests if the exception is an instance of the specified type.
+ virtual bool isInstanceOf( const Type &type ) const;
- static Type type();
+ /// Type of this exception.
+ static Type type();
-private:
- // VC++ does not recognize call to parent class when prefixed
- // with a namespace. This is a workaround.
- typedef std::exception SuperClass;
+protected:
+ // VC++ does not recognize call to parent class when prefixed
+ // with a namespace. This is a workaround.
+ typedef std::exception SuperClass;
- std::string m_message;
- SourceLine m_sourceLine;
+ Message m_message;
+ SourceLine m_sourceLine;
+ std::string m_whatMessage;
};