|
|
||||||||||||||
Class Win32Exceptionpublic 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 ConstructorsWin32Exceptionpublic Win32Exception(int errorcode); Win32Exceptionpublic Win32Exception(int errorcode, String message); MethodsgetErrorCodepublic int getErrorCode(); getErrorDescriptionpublic static String getErrorDescription(int errorcode);
|
© 1998 Microsoft Corporation. All rights reserved. Terms of use. |