Packages
 In this topic

*Constructors

*Methods

 

Packages   PreviousThis Package
Package com.ms.dll   Previous This
Package

 


Class Win32Exception

public class Win32Exception extends RuntimeException
{
  // Constructors
  public Win32Exception(int errorcode);
  public Win32Exception(int errorcode, String message);

  // Methods
  public int getErrorCode();
  public static String getErrorDescription(int errorcode);
}

This class provides access to objects that contain error codes and error descriptions for errors set by Microsoft® Win32® functions. To set an error code, a Win32 function must be imported using the @dll.import directive with the setLastError modifier. This modifier tells the Microsoft Win32 VM for Java to capture the error code immediately after invoking the method. To retrieve the error code, you can invoke the com.ms.dll.dllLib.getLastWin32Error method.

Suppose you have imported the Win32 function FindClose, which returns status information through the error code. You can call the FindClose method, retrieve the error code, and wrap the error code in a Win32Exception object as shown by the following example.


import com.ms.dll.*;

boolean successful = FindClose(hFindFile);
if (!successful) {
	  Win32Exception e = 
        new Win32Exception(DllLib.getLastWin32Error());   
}

Note You cannot reliably retrieve error codes by using the Win32 function GetLastError. This is because the Microsoft VM, while executing function calls of its own, might overwrite the error code before you retrieve it.

To learn how to import DLL functions such as FindClose, see the Syntax for @dll.import section of the Microsoft® J/Direct™ article.

RuntimeException
  |
  +--Win32Exception

Constructors

Win32Exception

public Win32Exception(int errorcode);

Creates a Win32Exception object initialized with an error code.

ParameterDescription
errorcode The error code.

Win32Exception

public Win32Exception(int errorcode, String message);

Creates a Win32Exception object initialized with an error code and an error description.

ParameterDescription
errorcode The error code.
message The error description.

Methods

getErrorCode

public int getErrorCode();

Retrieves the error code associated with the Win32Exception object.

Return Value:

Returns the error code associated with the Win32Exception object.

getErrorDescription

public static String getErrorDescription(int errorcode);

Retrieves the error description associated with a Win32 error code.

Return Value:

Returns the error description.

ParameterDescription
errorcode The error code.

upnrm.gif © 1998 Microsoft Corporation. All rights reserved. Terms of use.