1 // Exception 2 3 #ifndef _EXCEPTION_H 4 #define _EXCEPTION_H 5 6 #include <stdarg.h> 7 #include <stdio.h> 8 9 #include <String.h> 10 11 namespace BPrivate { 12 namespace Storage { 13 14 class Exception { 15 public: 16 // constructor 17 Exception() 18 : fError(B_OK), 19 fDescription() 20 { 21 } 22 23 // constructor 24 Exception(BString description) 25 : fError(B_OK), 26 fDescription(description) 27 { 28 } 29 30 // constructor 31 Exception(const char* format,...) 32 : fError(B_OK), 33 fDescription() 34 { 35 va_list args; 36 va_start(args, format); 37 SetTo(B_OK, format, args); 38 va_end(args); 39 } 40 41 // constructor 42 Exception(status_t error) 43 : fError(error), 44 fDescription() 45 { 46 } 47 48 // constructor 49 Exception(status_t error, BString description) 50 : fError(error), 51 fDescription(description) 52 { 53 } 54 55 // constructor 56 Exception(status_t error, const char* format,...) 57 : fError(error), 58 fDescription() 59 { 60 va_list args; 61 va_start(args, format); 62 SetTo(error, format, args); 63 va_end(args); 64 } 65 66 // copy constructor 67 Exception(const Exception& exception) 68 : fError(exception.fError), 69 fDescription(exception.fDescription) 70 { 71 } 72 73 // destructor 74 ~Exception() 75 { 76 } 77 78 // SetTo 79 void SetTo(status_t error, BString description) 80 { 81 fError = error; 82 fDescription.SetTo(description); 83 } 84 85 // SetTo 86 void SetTo(status_t error, const char* format, va_list arg) 87 { 88 char buffer[2048]; 89 vsprintf(buffer, format, arg); 90 SetTo(error, BString(buffer)); 91 } 92 93 // GetError 94 status_t Error() const 95 { 96 return fError; 97 } 98 99 // GetDescription 100 const char* Description() const 101 { 102 return fDescription.String(); 103 } 104 105 private: 106 status_t fError; 107 BString fDescription; 108 }; 109 110 }; // namespace Storage 111 }; // namespace BPrivate 112 113 #endif // _EXCEPTION_H 114 115 116