Export (0) Print
Expand All

Win32Exception Class

The exception that is thrown for a Win32 error code.

For a list of all members of this type, see Win32Exception Members.

System.Object
   System.Exception
      System.SystemException
         System.Runtime.InteropServices.ExternalException
            System.ComponentModel.Win32Exception
               System.Net.Sockets.SocketException

[Visual Basic]
<Serializable>
Public Class Win32Exception
   Inherits ExternalException
[C#]
[Serializable]
public class Win32Exception : ExternalException
[C++]
[Serializable]
public __gc class Win32Exception : public ExternalException
[JScript]
public
   Serializable
class Win32Exception extends ExternalException

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

Win32 error codes are translated from their numeric representations into a system message when they are displayed. Use NativeErrorCode to access the numeric representation of the error code associated with this exception. For information about the error codes, see "Win32 Error Codes" in the Platform SDK or in MSDN.

Example

[Visual Basic, C#, C++] The following example shows how to catch a Win32 exception and interpret its content. The sample attempts to start a nonexisting executable which results in throwing a Win32 exception. Upon catching the exception, the sample fetches the respective error message, code, and origin of the exception.

[Visual Basic] 
Dim myEx As New Win32Exception(-2147467259)
Console.WriteLine(myEx.Message)
Console.WriteLine(myEx.ErrorCode)
Console.WriteLine(myEx.HelpLink)
Console.WriteLine(myEx.Source)

[C#] 
Win32Exception myEx=new Win32Exception(-2147467259);
Console.WriteLine(myEx.Message);
Console.WriteLine(myEx.ErrorCode);
Console.WriteLine(myEx.HelpLink);
Console.WriteLine(myEx.Source);

[C++] 
Win32Exception* myEx = new Win32Exception(-2147467259);
Console::WriteLine(myEx->Message);
Console::WriteLine(myEx->ErrorCode);
Console::WriteLine(myEx->HelpLink);
Console::WriteLine(myEx->Source);

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.ComponentModel

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

Assembly: System (in System.dll)

See Also

Win32Exception Members | System.ComponentModel Namespace

Show:
© 2014 Microsoft