f



Mapping error codes to error messages #2

I need to make an error handling framework in which 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 standard C++ 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


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
9/28/2005 5:42:06 PM
comp.lang.c++.moderated 10738 articles. 1 followers. allnor (8509) is leader. Post Follow

5 Replies
1482 Views

Similar Articles

[PageSpeed] 39

I would use something like std::map<unsigned int, std::string>. The
unsigned int would be the error code and the std::string would be the
message for that error code.


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Dan
9/28/2005 10:03:50 PM
Andy wrote:
> I need to make an error handling framework in which 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 standard C++ 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.

I generally store my error messages in an array, and use error codes as
indexes into the array.  My error codes are usually enumerations; I
don't know whether enumerations as array indexes are quite kosher, but
they have worked for me.

If your error codes are distributed across a large space of integers,
you might use them as keys to a switch statement, with one case label
for each error code.

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Jeff
9/29/2005 2:56:56 PM
Dan McLeran wrote:
> I would use something like std::map<unsigned int,
> std::string>. The unsigned int would be the error code and the
> std::string would be the message for that error code.

Depending on how the error codes and messsages are being
maintained, char const*[] is likely the simplest solution.
(Note that if errors may occur during the construction of static
objects, a solution which uses static initialization is almost a
necessity.  So no std::string, no std::vector and no std::map.)

Of course, if the error codes are pre-defined, and very sparce,
this may not work.  If order of initialization is not a problem,
std::map is a very good solution.  Otherwise, I've found that
something like:

     static struct MessageMap
     {
         unsigned int        code ;
         char const*         message ;
     } const             map[] =
     {
         { Error1, "whatever went wrong" },
         //  ...
     }

works well.  Most of the time, a simple linear search
(std::find) is sufficient; if not, it's generally not too hard
to sort the table and use std::lower_bound on it.

--
James Kanze                                           GABI Software
Conseils en informatique orient�e objet/
                    Beratung in objektorientierter Datenverarbeitung
9 place S�mard, 78210 St.-Cyr-l'�cole, France, +33 (0)1 30 23 00 34


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
kanze
9/29/2005 8:31:11 PM
Andy wrote:

> I know this is not exactly standard C++ that we are
> discussing

It *is* a standard stuff, see std::messages class.
The fact is that I've never seen it used in practice - probably because
there are too many things that are left "implementation-defined".

> is anybody aware of any implementation techniques.

Go for the std::map solution as already suggested, it is easy to
implement and quite extensible as well.


--
Maciej Sobczak : http://www.msobczak.com/
Programming    : http://www.msobczak.com/prog/

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Maciej
9/29/2005 8:31:53 PM
Andy wrote:
> I need to make an error handling framework in which 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 standard C++ 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.

Do you have any internationalization concern (ie, do the error messages
need to be localized)?
If yes, the map <Error Code> <--> <Error Message> should be in some
kind of external resource (a file, a database, whatever is available on
your environment) and you should havesome kind of framework to retrieve
the correct translation, based on the current locale.

Arnaud


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
adebaene
9/29/2005 8:32:31 PM
Reply:

Similar Artilces:

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

Error: An error occurred while shelling out to mbuild (error code = 1). #2
uilding COM object... mcc -M -silentsetup -d 'D:/matlab2006/work/testww//src' -B 'ccom:testww,testwwclass,1.0' -g -S 'D:/matlab2006/work/testww.m' mwcomtypes.idl oaidl.idl objidl.idl unknwn.idl wtypes.idl ocidl.idl oleidl.idl servprov.idl urlmon.idl msxml.idl testww_idl.idl oaidl.idl objidl.idl unknwn.idl wtypes.idl ocidl.idl oleidl.idl servprov.idl urlmon.idl msxml.idl mwcomtypes.idl 'rc' &#19981;&#26159;&#20869;&#37096;&#25110;&#22806;&#37096;&#21629;&#2019 6;&#65292;&#20063;&#19981;&#26159;&#21487;&#...

Error: Windows SDK function returned an error. (Error code -12) #2
I get this error "Error: Windows SDK function returned an error. (Error code -12) The system cannot find the path specified." when I build an installer of my program in Labview. It is looking for a file but it is asking for&nbsp;the Measurement Studio CD. this is the message before the error. &nbsp; Copying products from distributionsCopying distribution 'NI Measurement Studio 8.1.2 for Visual Studio 2005' from: D:\VS2005\ to: C:\Program Files\National Instruments\Shared\ProductCache\ &nbsp; Please help. &nbsp; --Gio sentinel95, greetings! Did you bypass thi...

fpga -Re:ERROR MESSAGE INDICATIN X-FLOW PROGRAM MAP RETURNED ERROR CODE
sir, &nbsp; I am working on a project using ni rio-7831R uaing labview fpga1.1, on compiling on to the device i am encountering a error giving follow message: &nbsp; Problem encountered during the packing phase.ERROR:Xflow - Program map returned error code 2. Aborting flow execution... &nbsp; so please, recommend me the action so that i could compile my project without error. &nbsp; &nbsp; vamsi Hi Vamsi, The information you are looking for is in this KB: Why Does My FPGA Compile Give An OVERMAPPED Error When Compiling? &lt; <a href="http://digital.ni.com/publ...

(assert-error) tests errors and error messages
I wrote (assert-error) to make sure that a function generates an error, and verify the error message. What do you think? Below is the definition and a few test cases, for Emacs 22.1.50. (require 'cl) (defmacro assert-error (form &optional regexp) "FORM must signal an error. Signal an error otherwise. Additionally, the error message must match REGEXP. Case is ignored while matching REGEXP." (let ((msg (make-symbol "msg")) (ok (make-symbol "ok")) (res (make-symbol "res"))) `(let ((,ok nil)) (condition-case err ...

How to get the error message rather than the code error
Hi, After sending a request, I would get the possible error message. Not the code @@error, nor the exact content of sysmessages, but the message like it could be in the log file. TIA, TSalm TSalm (tsalm@free.fr) writes: > After sending a request, I would get the possible error message. > Not the code @@error, nor the exact content of sysmessages, but the > message like it could be in the log file. "Sending a request", that sounds like you are issuing a call from a client program. In that case you should be able to pick up the error message. If you tell which client API...

Error strings for os/2 error codes
Hello, Is there a function that returns a string for a given API return code? Like perror()? Or something equivalent to sys_errlist[]? -- jmm (hyphen) list (at) sohnen-moe (dot) com (Remove .AXSPAMGN for email) In <G4udnakUQqWJo2LbnZ2dnUVZ_tijnZ2d@giganews.com>, on 09/29/2007 at 11:11 PM, Jim Moe <jmm-list.AXSPAMGN@sohnen-moe.com> said: Hi, > Is there a function that returns a string for a given API return code? >Like perror()? Or something equivalent to sys_errlist[]? You are looking for DosGetMessage(). Steven -- --------------------------...

Error code when there is no error??
In my source I have: wndclass.hIcon = LoadIcon (hInstance, "test") ; test.ico is a valid icon. file. Everythig works ok. But when I test for an error like this: ShowLastError(); // no problems here wndclass.hIcon = LoadIcon (hInstance, "test") ; ShowLastError(); // I get "The system cannot find the file specidied" wndclass.hIcon get a valid handle. Here is my ShowLastError program: VOID ShowLastError(void) { LPVOID lpMsgBuf; DWORD error_code; int status; char sa1[1024]; error_code = Get...

C++ error message #2
Hi, I get this error message when I try to run any C++ program. I am using the GNU C++ compiler that comes with the Solaris 9 4/03 software companion CD. ld.s0.1: ./a.out: fatal: libstdc++.s0.2.10.0:open failed: No such file or directory --------------------------------------------------------------------- I was instructed to put the following into my ~/.bashrc file and reconfigure and recompile the program: export LDFLAGS='-L/opt/sfw/lib -R/opt/sfw/lib' If my sources don't use a GNU autoconf script then fix Makefiles manually, or put the above into the command for c...

How To Accessing C++ Class objects in C : getting error fatal error C1189: #error : "eh.h is only for C++!"
hi , i am Getting this Error fatal error C1189: #error : "eh.h is only for C++!" my Problem is i am Having C++ librabry and Appropriate .h file i want to Access Them is .c File Files..... to Be More Specific i am Creating a C++ Object in a C file... this Giving me the error!!! :( can Any Body Please Help me How to Access the C++ object in C file... Thanks In Advance :) Hi, > How to Access the C++ object in C file... Please have a look at the following page http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp.html Regards On Jan 7, 11:17=A0am, "sachinv1...@gmail.com" <sachinv1...@gmail.com> wrote: > hi , > i am Getting this Error > fatal error C1189: #error : "eh.h is only for C++!" > my Problem is i am Having C++ librabry and Appropriate .h file > i want to Access Them is .c File Files..... > to Be More Specific i am Creating a C++ Object in a C file... > this Giving me the error!!! :( > > can Any Body Please Help me > > How to Access the C++ object in C file... > Thanks In Advance :) In general, you can't. You can provide a procedural interface instead, and declare it in a header file like this: #ifdef __cplusplus extern "C" { #endif void some_function(int, char*, double); // or whatever #ifdef __cplusplus } #endif This can then be included from both C and C++. On Jan 7, 4:32=A0pm, tragomaskhalos <dave.du.verg...@logicacmg.com> wrote: > On Jan 7, 11:17=A0am, "...

[Urgent]: How To Accessing C++ Class objects in C : getting error fatal error C1189: #error : "eh.h is only for C++!"
hi , i am Getting this Error fatal error C1189: #error : "eh.h is only for C++!" my Problem is i am Having C++ librabry and Appropriate .h file i want to Access Them is .c File Files..... to Be More Specific i am Creating a C++ Object in a C file... this Giving me the error!!! :( can Any Body Please Help me How to Access the C++ object in C file... Thanks In Advance :) "sachinv1821@gmail.com" <sachinv1821@gmail.com> writes: > How to Access the C++ object in C file... > Thanks In Advance :) You'd be better off asking in comp.lang.c++. I know this sounds...

Error Code :17410 Error State :null Error Message :No more data to read from socket Stack Trace : java.sql.SQLException: No more data to read from socket
Hi, I see the following errors in the logs: Error Code :17410 Error State :null Error Message :No more data to read from socket Stack Trace : java.sql.SQLException: No more data to read from socket at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:114) at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:156) at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:803) at oracle.jdbc.ttc7.MAREngine.unmarshalUB1(MAREngine.java:731) at oracle.jdbc.ttc7.MAREngine.unmarshalSB1(MAREngine.java:690) at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:372) at oracle.jdbc.ttc7...

checking for error code and error message after calling EXEC
I have a stored procedure in which I EXECute some DDL statements (built dynamically). How can I check for an error code and error message? (I'm using version 12.5) ----- Posted via NewsOne.Net: Free (anonymous) Usenet News via the Web ----- http://newsone.net/ -- Free reading and anonymous posting to 60,000+ groups NewsOne.Net prohibits users from posting spam. If this or other posts made through NewsOne.Net violate posting guidelines, email abuse@newsone.net ...

Error message: Exception error within external code
Hi &nbsp; I am getting an error message on running one of my vi's that uses DAQ.mx that causes labview to close it reads: &nbsp; An exception occurred within the external code called by call library node.&nbsp; This might have corrupted LabVIEW's memory.&nbsp; Save any work to a new location and restart LabVIEW.&nbsp; "VI ......." was stopped at node OX19E4 DAQmx Start Task.vi. &nbsp; The odd thing is if I put execution highlighting on the vi runs ok and then continues to run OK untill I close Labview and restart it. &nbsp; Is anybody familiar wit...

Error code 500. Message: Internal Server Error.
A day ago, all of a sudden, I just started having a problem (only in Firefox (1.5.07) - NOT in Opera or IE_. When every I get to a site where where I link to an https page, I get this diagnostic: Error code 500. Message: Internal Server Error. These are two of the URLs that give me trouble: +++++++++++++++++++++++ https://www.google.com/accounts/ServiceLogin?service=mail&passive=tru... https://login.yahoo.com/config/login_verify2?.page=p1&.partner=&.intl... +++++++++++++++++++++++ I've uninstalled and reinstalled Firefox and have cleared all personal data, co...

When is an error not an error?
When it's OSS slopware, of course. http://www.angelfire.com/planet/dfs0/Knode_send_error.png On 2006-09-12 02:42, * DFS wrote: > When it's OSS slopware, of course. > > http://www.angelfire.com/planet/dfs0/Knode_send_error.png > Well, some time ago I had a problem with OE - too long reference line to other posts, and OE of course refused to send... then crashed. Should I name it a feature? -- Andrea On Tue, 12 Sep 2006 03:25:29 +0200, Andrea wrote: > On 2006-09-12 02:42, * DFS wrote: >> When it's OSS slopware, of course. >> >> http:/...

general: error: socket.c:1577: unexpected error: #2
I recently [8/1/2009] upgraded to 9.5.1P3. Last evening there were two brief moments that the named process was not resolving out of cache. This is a recursive only server that is basically opened to all clients, mostly for historical reasons. The named process recovered on its own. While I have seen references to old bugs/issues https://lists.isc.org/mailman/htdig/bind-users/2005-January/055224.html This seems to be something different. We're [still] on Red Hat Enterprise Linux AS release 3. Any advice on what to investigate? Thanks- -Michael Aug 17 01:24:53 name...

Error messages #2 #2
Hi, One question. I set to php.ini this error_reporting=E_ALL & ~E_NOTICE to be a list of error messages and some warnings/tips on the code written. All good, but if I have code like ------------------------ function foo(string $x) { echo($x); } foo("hi"); ------------------------ I got this error ------------------------ Catchable fatal error: Argument 1 passed to foo() must be an instance of string, string given, called in E:\Work\php\phpFramework\test.php on line 8 and defined in E:\Work\php\phpFramework\test.php on line 3 ------------------------ !!!but... is n...

error or not an error ...
I was just testing out the R4 REXX thingy, and it found an error in the following program. My question is this, is it an error or not? My PC/REXX and Regina don't barf on it, but I thought they should've. _____________________________________________ /**/ ?.='' ?.z='batman' trace i if ?.z\==''then do; say '?.z=' ?.z; end ______________________________________________ Note that there is space before the THEN. I'm not sure of the exact rules for parsing an IF statement, I know that THEN is a "reserved" keyword when an IF statement is...

When is an error not an error?
The Java language specification claims in: 8.8.7.1 Explicit Constructor Invocations .... "If an anonymous class instance creation expression appears within an explicit constructor invocation statement, then the anonymous class may not refer to any of the enclosing instances of the class whose constructor is being invoked." Helpfully it gives an example: "For example: class Top { int x; class Dummy { Dummy(Object o) {} } class Inside extends Dummy { Inside() { super(new Object() { int r = x; }); // err...

Over 2 million error messages in .xsessions-error file. Help!
I noticed that my ~ .xsession-errors file had grown huge. It had over 2 million lines of messages like this: Gecko:3547): Gdk-CRITICAL **: gdk_pixbuf_get_from_drawable: assertion `gdk_window_is_viewable (src)' failed (Gecko:3547): GdkPixbuf-CRITICAL **: gdk_pixbuf_get_n_channels: assertion `pixbuf != NULL' failed (Gecko:3547): GdkPixbuf-CRITICAL **: gdk_pixbuf_get_bits_per_sample: assertion `pixbuf != NULL' failed (Gecko:3547): GdkPixbuf-CRITICAL **: gdk_pixbuf_get_width: assertion `pixbuf != NULL' failed (Gecko:3547): GdkPixbuf-CRITICAL **: gdk_pixbuf_get_height: asse...

Error message #2 #2
I have been working all afternoon developing a database and then disaster hit. I accidently typed a "d" in a property field and didn't realize it and closed the window. I am getting the following message. "the Microsoft Jet database engine cannot find theinput table or query 'D' Mkae sure it exists and that its name is spelled correctly." I can still open the database, but only in design view. My "Help" feature isn't working now either. I can't believe I will have to start all over. Any ideas from anyone? ...

Error message #2 #2
Hi! I can't run LV, I get everytime thins error: Compiler error. Report this problem to ni tech support. copy cvt str/pict/tag, csrc=0x40 ...

error vb : 3000 : Reserved error (-5400) there is no message for this error
Hello, i have a problem when i connect an access 97 database with an text file "3000 Reserved error (-5400); there is no message for this error." The attachment is an example of a textfile that i want to connect through vb 6.0 vb code : strtable = "FileName" strconnect = "Text;HDR=NO;IMEX=2;FMT=Fixed;Database=c:\temp" strSourcetable = "MAILGV2939.TXT" Set tdfLinked = dbsTemp.CreateTableDef(strTable) tdfLinked.Connect = strConnect tdfLinked.SourceTableName = strSourceTable dbsTemp.TableDefs.Append tdfLinked what is the solution to this pro...

Web resources about - Mapping error codes to error messages #2 - comp.lang.c++.moderated

Message - Wikipedia, the free encyclopedia
A message is a discrete unit of communication intended by the source for consumption by some recipient or group of recipients. A message may ...

Shaun Kenny-Dowall texts: The explicit messages to and from Jessica Peris - DailyTelegraph Search Search ...
HE scolded her for taking cocaine, accused her of cheating on him and threatened to throw her out of his house.

Grindr founder Joel Simkhai has a Mardi Gras message for Malcolm Turnbull
Gay entrepreneur urges Turnbull government to support equality.

Brazil frees imprisoned Facebook exec who couldn’t decrypt WhatsApp messages
(credit: Jeso Carneiro ) A Brazilian judge has ordered the release of a Facebook executive one day after he was jailed in São Paulo for "repeated ...

Anonymous hacks Donald Trump's voicemail and leaks the messages
In the run-up to the presidential election, few days go by when Donald Trump isn't hitting the headlines for something he's said or done. The ...

A Message From Queen Elizabeth the Second, by the Grace of God Queen of this Realm and of Her other Realms ...
By Queen Elizabeth the Second, by the Grace of God Queen of this Realm and of Her other Realms and Territories, Head of the Commonwealth, Defender ...

Cops have message for whoever left drugs in hotel
"We feel horrible for your loss," police in Macedonia, Ohio wrote in a tongue-in-check Facebook post

Christian removed from EasyJet flight over 'prayer' message on his phone
A Christian has been removed from an EasyJet flight after a passenger saw a WhatsApp message on his phone and thought he might be a terrorist. ...

Educators update anti-bullying messages to protect Muslims
MERIDEN, Conn. (AP) — In response to a surge in reports of anti-Muslim bullying — students being called terrorists, having their head scarves ...

America’s Message To The New Canadian Prime Minister – Innovation Matters
Obama shouldn’t hesitate to hold Trudeau’s feet to the fire on his campaign promises to jumpstart Canada’s flagging economy.

Resources last updated: 3/6/2016 6:55:56 PM