Here's a first shot at an exception class:
class OpenCardError : public exception // Uses ANSI class.
{
unsigned long mSituation; // ID of situation error happened in.
unsigned long mErrorCode; // Cross-platform error code.
public:
OpenCardError( unsigned long sit ) : mSituation(sit) {};
virtual const char* GetErrorMessage(); // Return error string.
};
I know GetErrorMessage() appears to be a stupid implementation when you
consider localization, but I intend to have it call a standardized
string-fetching routine which will fix the localizing problem. The default
implementation of GetErrorMessage() would fetch the appropriate situation
and error strings based on mSituation and mErrorCode and then concatenate
them to generate an error message. For more complex errors, we creplace
placeholders in an overridden GetErrorMessage() to fill in additional
information (like the handler we failed in or the amount of memory we'd
have needed).
This class would be easily subclassable for simple errors by changing the
error code in the constructor.
It has some advantages over Anthony's exception classes in HyperInterp
(which i took as a template):
- A standardized way to get at the error message. The specifics are only
known to the class and the one who throws the exception, which allows to
keep the code much more generic. No need to "if" etc. when displaying
errors.
- It's a class, not a struct, which is more C++-like
BTW, Anthony, I'm not sure whether we should use the ": mSituation(sit)"
syntax in our classes (you seem to do this a lot), as I'm not sure every
compiler supports this, and it's also less clear whether it's a variable
being set or a function being called. Could become confusing during
debugging.
Cheers,
-- M. Uli Kusterer
------------------------------------------------------------
http://www.weblayout.com/witness
'The Witnesses of TeachText are everywhere...'
--- HELP SAVE HYPERCARD: ---
Details at: http://www.hyperactivesw.com/SaveHC.html
Sign: http://www.giguere.uqam.ca/petition/hcpetition.html