System Error Code

Source: Internet
Author: User

When you call a Windows function, it validates the parameters that you pass to it and then attempts to perform its duty. if you pass an invalid parameter or if for some other reason the action cannot be med, the function's return value indicates that the function fails in some way.

When a Windows function returns with an error code, it's frequently useful to understand why the function failed. microsoft has compiled a list of all possible error codes and has assigned each error code a 32-bit number.

Internally, when a Windows function detects an error, it uses a mechanic called thread-local storage to associate the appropriate error-code number with the calling thread.

This mechanism allows threads to run independently of each other without affecting each other's error codes. when the function returns to you, its return value indicates that an error has occurred. to see exactly which error this is, callGetLastErrorFunction:

DWORD GetLastError();

This function simply returns the thread's 32-bit error code set by the last function call. each error has three representations: a message ID (a macro that you can use in your source code to compare against the return valueGetLastError), Message text (an English text description of the error), and a number (which you shoshould avoid using and instead use the message ID ).

When a Windows function fails, you should callGetLastErrorRight away because the value is very likely to be overwritten if you call another Windows function. Notice that a Windows function that succeeds might overwrite this valueERROR_SUCCESS.

While debugging, I find it extremely useful to monitor the thread's last error code. in Microsoft Visual Studio, Microsoft's debugger supports a useful feature-you can configure the Watch window to always show you the thread's last error code number and the text description of the error. this is done by selecting a row in the Watch window and typing$ Err, hr.

Visual Studio also ships with a small utility called Error Lookup. You can use Error Lookup to convert an error code number into its textual description.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.