xref: /haiku/headers/tools/cppunit/cppunit/Exception.h (revision 58481f0f6ef1a61ba07283f012cafbc2ed874ead)
1 #ifndef CPPUNIT_EXCEPTION_H
2 #define CPPUNIT_EXCEPTION_H
3 
4 #include <cppunit/Portability.h>
5 #include <cppunit/SourceLine.h>
6 #include <exception>
7 #include <string>
8 
9 namespace CppUnit {
10 
11 /*! \brief Exceptions thrown by failed assertions.
12  * \ingroup BrowsingCollectedTestResult
13  *
14  * Exception is an exception that serves
15  * descriptive strings through its what() method
16  */
17 class CPPUNIT_API Exception : public std::exception
18 {
19 public:
20 
21     class Type
22     {
23     public:
Type(std::string type)24         Type( std::string type ) : m_type ( type ) {}
25 
26         bool operator ==( const Type &other ) const
27         {
28 	    return m_type == other.m_type;
29         }
30     private:
31         const std::string m_type;
32     };
33 
34 
35     Exception( std::string  message = "",
36 	       SourceLine sourceLine = SourceLine() );
37 
38 #ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED
39     Exception( std::string  message,
40 	       long lineNumber,
41 	       std::string fileName );
42 #endif
43 
44     Exception (const Exception& other);
45 
46     virtual ~Exception () throw();
47 
48     Exception& operator= (const Exception& other);
49 
50     const char *what() const throw ();
51 
52     SourceLine sourceLine() const;
53 
54 #ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED
55     long lineNumber() const;
56     string fileName() const;
57 
58     static const std::string UNKNOWNFILENAME;
59     static const long UNKNOWNLINENUMBER;
60 #endif
61 
62     virtual Exception *clone() const;
63 
64     virtual bool isInstanceOf( const Type &type ) const;
65 
66     static Type type();
67 
68 private:
69     // VC++ does not recognize call to parent class when prefixed
70     // with a namespace. This is a workaround.
71     typedef std::exception SuperClass;
72 
73     std::string m_message;
74     SourceLine m_sourceLine;
75 };
76 
77 
78 } // namespace CppUnit
79 
80 #endif // CPPUNIT_EXCEPTION_H
81 
82