> I need to make an error handling framework to be used by C++
> applications running on HP-UX. In this, the application error codes can
> be mapped to pre-defined error messages. The framework would have C++
> exception classes for error information propagation. I however have no
> clue on how to map the error codes to the messages, and efficiently
> access the messages through a simple mapping class or function. I know
> this is not exactly a UNIX question that we are discussing, but is
> anybody aware of any implementation techniques. Should it necessarily
> be a static array indexed by error codes or some rehash of the error
Usually you don't have to handle 1e9 errors at once.
Therefore there's absolutely NO need for efficiency.
If you have a BIG number of different error messages, you could even
store them away on the internet and fetch them thru HTTP when needed,
to free RAM and HD space, (and thus improving performance of the
Ok, only joking about storing them on the Internet, but really.
Just do it the simplier you can: an indexed array. It can be
statically allocated if the error messages are not localized, or you
can load it lazily from a file according to the localization. You
only need to allocate the error numbers more or less sequentially.
If you cannot do that, then just store in the array the couples (error
number, error message), and don't bother implementing anything else
than a sequential search for the error number. Remember, error never
occurs, and when they do, you can execute more than 1 billion
instructions in less than one second on current hardware!
__Pascal Bourguignon__ http://www.informatimago.com/
The rule for today:
Touch my tail, I shred your hand.
New rule tomorrow.