338b8dc301
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14574 a95241bf-73f2-0310-859d-f6bbb57e9c96
116 lines
1.7 KiB
C++
116 lines
1.7 KiB
C++
// Exception
|
|
|
|
#ifndef _EXCEPTION_H
|
|
#define _EXCEPTION_H
|
|
|
|
#include <stdarg.h>
|
|
#include <stdio.h>
|
|
|
|
#include <String.h>
|
|
|
|
namespace BPrivate {
|
|
namespace Storage {
|
|
|
|
class Exception {
|
|
public:
|
|
// constructor
|
|
Exception()
|
|
: fError(B_OK),
|
|
fDescription()
|
|
{
|
|
}
|
|
|
|
// constructor
|
|
Exception(BString description)
|
|
: fError(B_OK),
|
|
fDescription(description)
|
|
{
|
|
}
|
|
|
|
// constructor
|
|
Exception(const char* format,...)
|
|
: fError(B_OK),
|
|
fDescription()
|
|
{
|
|
va_list args;
|
|
va_start(args, format);
|
|
SetTo(B_OK, format, args);
|
|
va_end(args);
|
|
}
|
|
|
|
// constructor
|
|
Exception(status_t error)
|
|
: fError(error),
|
|
fDescription()
|
|
{
|
|
}
|
|
|
|
// constructor
|
|
Exception(status_t error, BString description)
|
|
: fError(error),
|
|
fDescription(description)
|
|
{
|
|
}
|
|
|
|
// constructor
|
|
Exception(status_t error, const char* format,...)
|
|
: fError(error),
|
|
fDescription()
|
|
{
|
|
va_list args;
|
|
va_start(args, format);
|
|
SetTo(error, format, args);
|
|
va_end(args);
|
|
}
|
|
|
|
// copy constructor
|
|
Exception(const Exception& exception)
|
|
: fError(exception.fError),
|
|
fDescription(exception.fDescription)
|
|
{
|
|
}
|
|
|
|
// destructor
|
|
~Exception()
|
|
{
|
|
}
|
|
|
|
// SetTo
|
|
void SetTo(status_t error, BString description)
|
|
{
|
|
fError = error;
|
|
fDescription.SetTo(description);
|
|
}
|
|
|
|
// SetTo
|
|
void SetTo(status_t error, const char* format, va_list arg)
|
|
{
|
|
char buffer[2048];
|
|
vsprintf(buffer, format, arg);
|
|
SetTo(error, BString(buffer));
|
|
}
|
|
|
|
// GetError
|
|
status_t Error() const
|
|
{
|
|
return fError;
|
|
}
|
|
|
|
// GetDescription
|
|
const char* Description() const
|
|
{
|
|
return fDescription.String();
|
|
}
|
|
|
|
private:
|
|
status_t fError;
|
|
BString fDescription;
|
|
};
|
|
|
|
}; // namespace Storage
|
|
}; // namespace BPrivate
|
|
|
|
#endif // _EXCEPTION_H
|
|
|
|
|