How do you know what a particular error code means?

So you're debugging your program, and all of a sudden you get this wierd error code - say error 0x00000011.  How do you know what that message means?

Well, one way is to memorize the entire Win32 error return code set, but that's got some issues.

Another way, if you have the right debugger extension is to use the !error extension - it will return the error text associated with the error.  There's a similar trick for dev studio (although I'm not sure what it is since I don't use the devstudio debugger)

But sometimes you're not running under windbg or devstudio and you've got a Win32 error code to look up.

And here's where the clever trick comes in.  You see, there's a complete list of error codes built into the system.  It's buried in the NET.EXE command that's used for network administration.

If you type "NET HELPMSG <errorno>" on the command line, you'll get a human readable version of the error code. 

So:

C:\>net helpmsg 17The system cannot move the file to a different disk drive.

It's a silly little trick, but I've found it extraordinarily useful.

Comments

  • Anonymous
    May 25, 2005
    FYI: net helpmsg does not know about COM errors (and more I guess). A nice utility available for download at Microsoft.com is "err" [1], which knows about those too.

    [1] http://www.microsoft.com/downloads/details.aspx?FamilyId=BE596899-7BB8-4208-B7FC-09E02A13696C&displaylang=en
  • Anonymous
    May 25, 2005
    Andreas, it does. You just need to type the HRESULT in as a decimal number.
  • Anonymous
    May 25, 2005
    >> Well, one way is to memorize the entire Win32 error return code set, but that's got some issues. <<

    Haha. The primary issue being not everyone's a Raymond.
  • Anonymous
    May 25, 2005
    Oh, it does? Either I've misunderstood the hex to decimal conversion or my version doesn't support that :(

    Here is the output I get for some attempts (note that I removed some whitespace and "$ " is the prompt):

    1) Just try the hex-HRESULT
    $ net helpmsg 0x80004002
    The syntax of this command is:
    NET HELPMSG
    message#

    [Does not work, as expected based on your comment above]
    2) Convert the hex to decimal and run it again
    $ net helpmsg -2147467262
    The syntax of this command is:
    NET HELPMSG
    message#

    [Huh, shouldn't this work??]

    3) Decimal with 'err'
    $ err -2147467262
    Error string for error -2147467262 (0x80004002) is:
    No such interface supported

    4) Hex with 'err'
    $ err 0x80004002
    Error string for error -2147467262 (0x80004002) is:
    No such interface supported
  • Anonymous
    May 25, 2005
    Andreas, net only takes unsigned integers, not signed integers. Having said that, trying the unsigned version of 0x80004002 still fails.

    Which implies that the error text isn't wherever FORMAT_MESSAGE_FROM_SYSTEM gets it.
  • Anonymous
    May 25, 2005
    The way to do it in visual studio is to append ",hr" (without quotes) to the variable that contains an error code. Very useful, can also accept hex.

    In fact, something I didn't know about VC6 (yes, I still use VC6) until recently is that you can create your own watch strings by writing a simple extension..
  • Anonymous
    May 25, 2005
    I think it's kind of awesome that for all the errors across the win32 system none were reused. (As far as I know.) How did you keep track of that? Did every product group get a chunk of error codes to assign as they saw fit?
  • Anonymous
    May 25, 2005
    foxyshadis: It's actually quite simple. There's a single header file winerror.h that's checked into the tree.

    Everyone who contributes to the base project and adds error codes to the base codebase (and that's a relatively limited set of people) modifies the same source file. So no collisions.

    The other product groups have their own header files that define their own error codes, if they're using COM they use the facility codes to differentiate between the products.
  • Anonymous
    May 25, 2005
    Mike said:
    The way to do it in visual studio is to append ",hr" (without quotes) to the variable that
    contains an error code. Very useful, can also accept hex.

    Another useful tip for Visual Studio is the psuedo-register ERR. It contains the result of calling GetLastError(). Putting "ERR,hr" in your watch window is a useful way to find out why the last API failed.
  • Anonymous
    May 25, 2005
    I have a program downloaded from Microsoft somewhere called "errlook" that allow you to specify the module to look for an error code.

    If no module is specified, Win32 error code is assumed.

    Very handy indeed.
  • Anonymous
    May 25, 2005
    @ERR,hr and @EAX,hr are always at the top of my watch list in VC. errlook.exe is a nice util because you can get string descriptions of errors where the strings are in other DLLs (from message table resources I suppose). So you can use it to get a string for error 12001 from wininet.dll.
  • Anonymous
    May 25, 2005
    Start - Programs - Microsoft Visual Studio 6.0 - Microsoft Visual Studio 6.0 Tools - Error Lookup
    invokes ERRLOOK.EXE which gives the same information.

    If both VS6 and VS2003 are installed then ERRLOOK.EXE still works, but VS2003 takes control of it and weirds up the GUI. Minimizing, restoring, disappearing from the Windows taskbar, etc. Can't find out what errors are occuring in the GUI because no one's displaying an error number to look up.
  • Anonymous
    May 25, 2005
    The comment has been removed
  • Anonymous
    May 26, 2005
    I used to use "Visual C++ error lookup" tool of visual studio.

    It would be better if "net helpmsg 0x00000011" works.
  • Anonymous
    May 26, 2005
    Two tools you should be aware of:

    Courtesy of John Durant, in his mention of BillG's talking about...
  • Anonymous
    May 27, 2005
    The DevStudio trick is to type "@err,hr&quot; in the watch window.

    Alon