btrfs: [] on the end of a struct field is a variable length array.
[haiku.git] / headers / private / storage / Exception.h
blobc5a4cc06824a9f58e349d50cd51fddb011fb8496
1 // Exception
3 #ifndef _EXCEPTION_H
4 #define _EXCEPTION_H
6 #include <stdarg.h>
7 #include <stdio.h>
9 #include <String.h>
11 namespace BPrivate {
12 namespace Storage {
14 class Exception {
15 public:
16 // constructor
17 Exception()
18 : fError(B_OK),
19 fDescription()
23 // constructor
24 Exception(BString description)
25 : fError(B_OK),
26 fDescription(description)
30 // constructor
31 Exception(const char* format,...)
32 : fError(B_OK),
33 fDescription()
35 va_list args;
36 va_start(args, format);
37 SetTo(B_OK, format, args);
38 va_end(args);
41 // constructor
42 Exception(status_t error)
43 : fError(error),
44 fDescription()
48 // constructor
49 Exception(status_t error, BString description)
50 : fError(error),
51 fDescription(description)
55 // constructor
56 Exception(status_t error, const char* format,...)
57 : fError(error),
58 fDescription()
60 va_list args;
61 va_start(args, format);
62 SetTo(error, format, args);
63 va_end(args);
66 // copy constructor
67 Exception(const Exception& exception)
68 : fError(exception.fError),
69 fDescription(exception.fDescription)
73 // destructor
74 ~Exception()
78 // SetTo
79 void SetTo(status_t error, BString description)
81 fError = error;
82 fDescription.SetTo(description);
85 // SetTo
86 void SetTo(status_t error, const char* format, va_list arg)
88 char buffer[2048];
89 vsprintf(buffer, format, arg);
90 SetTo(error, BString(buffer));
93 // GetError
94 status_t Error() const
96 return fError;
99 // GetDescription
100 const char* Description() const
102 return fDescription.String();
105 private:
106 status_t fError;
107 BString fDescription;
110 }; // namespace Storage
111 }; // namespace BPrivate
113 #endif // _EXCEPTION_H