BPicture: Fix archive constructor.
[haiku.git] / src / tools / restest / Exception.h
blob59c4aada4ea08e77a77297122e9e1db0dea94661
1 // Exception
3 #ifndef EXCEPTION_H
4 #define EXCEPTION_H
6 #include <stdarg.h>
7 #include <stdio.h>
9 #include <String.h>
11 class Exception {
12 public:
13 // constructor
14 Exception()
15 : fError(B_OK),
16 fDescription()
20 // constructor
21 Exception(BString description)
22 : fError(B_OK),
23 fDescription(description)
27 // constructor
28 Exception(const char* format,...)
29 : fError(B_OK),
30 fDescription()
32 va_list args;
33 va_start(args, format);
34 SetTo(B_OK, format, args);
35 va_end(args);
38 // constructor
39 Exception(status_t error)
40 : fError(error),
41 fDescription()
45 // constructor
46 Exception(status_t error, BString description)
47 : fError(error),
48 fDescription(description)
52 // constructor
53 Exception(status_t error, const char* format,...)
54 : fError(error),
55 fDescription()
57 va_list args;
58 va_start(args, format);
59 SetTo(error, format, args);
60 va_end(args);
63 // copy constructor
64 Exception(const Exception& exception)
65 : fError(exception.fError),
66 fDescription(exception.fDescription)
70 // destructor
71 ~Exception()
75 // SetTo
76 void SetTo(status_t error, BString description)
78 fError = error;
79 fDescription.SetTo(description);
82 // SetTo
83 void SetTo(status_t error, const char* format, va_list arg)
85 char buffer[2048];
86 vsprintf(buffer, format, arg);
87 SetTo(error, BString(buffer));
90 // GetError
91 status_t GetError() const
93 return fError;
96 // GetDescription
97 const char* GetDescription() const
99 return fDescription.String();
102 private:
103 status_t fError;
104 BString fDescription;
107 #endif // EXCEPTION_H