Exception.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #ifndef CPPUNIT_EXCEPTION_H
  2. #define CPPUNIT_EXCEPTION_H
  3. #include <cppunit/Portability.h>
  4. #include <cppunit/Message.h>
  5. #include <cppunit/SourceLine.h>
  6. #include <exception>
  7. CPPUNIT_NS_BEGIN
  8. /*! \brief Exceptions thrown by failed assertions.
  9. * \ingroup BrowsingCollectedTestResult
  10. *
  11. * Exception is an exception that serves
  12. * descriptive strings through its what() method
  13. */
  14. class CPPUNIT_API Exception : public std::exception
  15. {
  16. public:
  17. /*! \brief Constructs the exception with the specified message and source location.
  18. * \param message Message associated to the exception.
  19. * \param sourceLine Source location related to the exception.
  20. */
  21. Exception( const Message &message = Message(),
  22. const SourceLine &sourceLine = SourceLine() );
  23. #ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED
  24. /*!
  25. * \deprecated Use other constructor instead.
  26. */
  27. Exception( std::string message,
  28. long lineNumber,
  29. std::string fileName );
  30. #endif
  31. /*! \brief Constructs a copy of an exception.
  32. * \param other Exception to copy.
  33. */
  34. Exception( const Exception &other );
  35. /// Destructs the exception
  36. virtual ~Exception() throw();
  37. /// Performs an assignment
  38. Exception &operator =( const Exception &other );
  39. /// Returns descriptive message
  40. const char *what() const throw();
  41. /// Location where the error occured
  42. SourceLine sourceLine() const;
  43. /// Message related to the exception.
  44. Message message() const;
  45. /// Set the message.
  46. void setMessage( const Message &message );
  47. #ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED
  48. /// The line on which the error occurred
  49. long lineNumber() const;
  50. /// The file in which the error occurred
  51. std::string fileName() const;
  52. static const std::string UNKNOWNFILENAME;
  53. static const long UNKNOWNLINENUMBER;
  54. #endif
  55. /// Clones the exception.
  56. virtual Exception *clone() const;
  57. protected:
  58. // VC++ does not recognize call to parent class when prefixed
  59. // with a namespace. This is a workaround.
  60. typedef std::exception SuperClass;
  61. Message m_message;
  62. SourceLine m_sourceLine;
  63. std::string m_whatMessage;
  64. };
  65. CPPUNIT_NS_END
  66. #endif // CPPUNIT_EXCEPTION_H