|
Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members File Members
EkError Class ReferenceBase class for error objects.
More...
#include <EkError.h>
Inheritance diagram for EkError: [legend]Collaboration diagram for EkError:[legend]List of all members.
Detailed Description
Base class for error objects.
Specialized error object classes may be derived from this base class. Such classes would add data members to hold domain-specific error information, accessor functions to retrieve such data, and their own getMsg() function to produce a comprehensible human-readable message that describes the error.
This class may also be used by itself to create minimal, unspecialized error objects.
EkError objects characterize errors with the following information:
component - a SPmtString that names the software component that created the error. code - a numeric error code. Software components will probably create an enum to hold their various error codes. line - source file line number where the error object was created. filename - name of source file timestamp - time and date when error obejct was created
The component, code, line and fileName are all parameters to the EkError constructor. The WHERE macro provides a convenient shorthand for providing the the line and filename values to the constructor
The getMsg() function returns a text SPmtString that describes the error. getMsg() is a virtual function, and it is expected that derived classes will redefine it to produce appropriate descriptions for the errors they encompass. The default implementation of getMsg() is pretty simpleminded. This virtual function allows general purpose error logging and reporting code to be written that handle just EkErrors or EkErrps without needing to know the actual derived classes of the errors.
The default constructor allows uninitialized error obejcts to be created. These are identifiable byuse of the "isInitialized()" method. Debug versions will catch attempted use of uninitialized error objects by failure of "assert()" calls. If the "assert" mechanism is defeated, as in release code, uninitialized error objects may appear in error logs and displays. They are characterized by component code "EkError" and error code 0.
Things to consider when creating a derived error class:
- Make filename and line the last two parameters of the constructor, Default them to "<File name unknown>" and 0.
- Create a getMsg() function that creates a SPmtString in myMessage that describes the error.
- If your class adds data members that are pointers, make sure to provide a copy constructor, an operator=, and a destructor that do the right thing.
Example: (boring bits elided by ellipses: "...")
OrderError - a derived error class containing an order number class OrderError : public EkError
{
public:
OrderError(const char* component, int errcode, OrderId order,
const char* filename = "<file name unknown>", int line = 0);
OrderId getOrderId();
virtual const char* getMsg();
static const char* const className;
protected:
OrderId myOrderId;
}
const char* const OrderError::classname = "OrderError";
OrderError::OrderError(const char* component, int errcode, OrderId order,
const char* filename, int line)
: EkError(component, errcode, filename, line), myOrderId(order)
{
myClassName = OrderError::className;
}
EkErrp someFunction(...)
{
...
if(...error discovered...)
{
EkErrp ep(new OrderError(ORDER_ENTRY, BAD_COUNT, OrderNo, WHERE));
return ep;
}
...
}
EkErrp ep = someFunction();
if(ep)
{
errorLog.write(ep);
statusLine.displayMessage(ep->getMessage());
if(ep->getClassName() == OrderError::className)
cancelOrder(((OrderError*)ep)->getOrderId);
}
Constructor & Destructor Documentation
EkError::EkError |
( |
const char * |
component, |
|
|
int |
errcode, |
|
|
const char * |
filename = "< file name unknown >", |
|
|
int |
line = 0 |
|
) |
|
|
EkError::EkError |
( |
const EkError & |
|
) |
|
|
EkError::~EkError |
( |
|
) |
throw () [virtual] |
|
Member Function Documentation
const int & EkError::errcode |
( |
|
) |
const |
|
const char * EkError::getMsg |
( |
|
) |
const [virtual] |
|
bool EkError::isA |
( |
const char * |
component, |
|
|
int |
errcode |
|
) |
const |
|
bool EkError::isInitialized |
( |
|
) |
const |
|
const int & EkError::line |
( |
|
) |
const |
|
bool EkError::operator< |
( |
const EkError & |
rhs |
) |
const [inline] |
|
EkError & EkError::operator= |
( |
const EkError & |
|
) |
|
|
bool EkError::operator== |
( |
const EkError & |
rhs |
) |
const [inline] |
|
void EkError::print |
( |
ostream & |
os |
) |
const |
|
EkError & EkError::setMsg |
( |
const char * |
|
) |
|
|
const time_t & EkError::timestamp |
( |
|
) |
const |
|
const char * EkError::what |
( |
|
) |
const throw () [virtual] |
|
Friends And Related Function Documentation
friend class EkErrp [friend]
|
|
Member Data Documentation
bool EkError::mInitialized [protected]
|
|
int EkError::mMyCode [protected]
|
|
int EkError::mMyLine [protected]
|
|
time_t EkError::mMyTimestamp [protected]
|
|
bool EkError::msUseDate = true [static]
|
|
bool EkError::msUseLines = true [static]
|
|
The documentation for this class was generated from the following files:
|