f



Mapping error codes to error messages

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
codes.

Cheers,
Andy

0
9/28/2005 4:40:29 PM
comp.unix.programmer 10848 articles. 0 followers. kokososo56 (350) is leader. Post Follow

2 Replies
1333 Views

Similar Articles

[PageSpeed] 50

garth_rockett@yahoo.com writes:

> 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
> codes.

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
normal operations).

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.
0
Pascal
9/28/2005 5:01:06 PM
>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
>codes.

You might look at the com_err package.  It allows modular coding
with each module having its own set (something like 255 messages,
and a module can have more than one set if necessary) of error
messages, which it registers.  Any module can get text for any error
code, even if it is generated by another module.  It also handles
system error codes.

com_err comes as part of contributed software with FreeBSD and just
might already be on HP-UX.

					Gordon L. Burditt
0
gordonb
9/28/2005 5:40:15 PM
Reply: