DelphiFAQ Home Search:

When is a EWin32Error exception raised?

 

commentsThis article has not been rated yet. After reading, feel free to leave comments and rate it.

Question:

What is the EWin32Error exception good for?

Answer:

As of release 3, Delphi has a SysUtils routine called Win32Check() which you can pass an API result to. If it is False, it will raise an EWin32Error exception which is given the descriptive message. If you don't like to raise an exception, you can use GetLastError() and pass the error code to SysErrorMessage() to get a descriptive string (it's actually the same string that the exception will have as a message).

Below is an example written in Delphi 7.

begin
  // send a message to a non-existing window
  // unless you coincidentally happen to have 
  // a window handle 321. In that case just run this twice :-)
  SendMessage(321, WM_CLOSE, 0, 0);

  // this will show the error message directly
  ShowMessage(SysErrorMessage(GetLastError));

  // OR use your application's exception handling code
  RaiseLastOSError;  // throws an exception

  // note: 'OR' means: only use one of the two. 
  // Do not call GetLastError() twice.

Comments:

 

 

Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option.
 
It seems that you are
from Los Angeles, US .

Info/ Feedback on this

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:
photo Add a picture:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity. The owner of this web site reserves the right to delete such material.