Win32Exception Constructors

Definition

Initializes a new instance of the Win32Exception class.

Overloads

Win32Exception()

Initializes a new instance of the Win32Exception class with the last Win32 error that occurred.

Win32Exception(Int32)

Initializes a new instance of the Win32Exception class with the specified error.

Win32Exception(String)

Initializes a new instance of the Win32Exception class with the specified detailed description.

Win32Exception(Int32, String)

Initializes a new instance of the Win32Exception class with the specified error and the specified detailed description.

Win32Exception(SerializationInfo, StreamingContext)
Obsolete.

Initializes a new instance of the Win32Exception class with the specified context and the serialization information.

Win32Exception(String, Exception)

Initializes a new instance of the Win32Exception class with the specified detailed description and the specified exception.

Win32Exception()

Source:
Win32Exception.cs
Source:
Win32Exception.cs
Source:
Win32Exception.cs

Initializes a new instance of the Win32Exception class with the last Win32 error that occurred.

C#
public Win32Exception();

Remarks

The detailed description of the error will be determined by the Win32 error message associated with the error.

This constructor uses the GetLastWin32Error method of Marshal to get its error code.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Win32Exception(Int32)

Source:
Win32Exception.cs
Source:
Win32Exception.cs
Source:
Win32Exception.cs

Initializes a new instance of the Win32Exception class with the specified error.

C#
public Win32Exception(int error);

Parameters

error
Int32

The Win32 error code associated with this exception.

Remarks

The detailed description of the error is determined by the Win32 error message associated with the error.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Win32Exception(String)

Source:
Win32Exception.cs
Source:
Win32Exception.cs
Source:
Win32Exception.cs

Initializes a new instance of the Win32Exception class with the specified detailed description.

C#
public Win32Exception(string message);
C#
public Win32Exception(string? message);

Parameters

message
String

A detailed description of the error.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Win32Exception(Int32, String)

Source:
Win32Exception.cs
Source:
Win32Exception.cs
Source:
Win32Exception.cs

Initializes a new instance of the Win32Exception class with the specified error and the specified detailed description.

C#
public Win32Exception(int error, string message);
C#
public Win32Exception(int error, string? message);

Parameters

error
Int32

The Win32 error code associated with this exception.

message
String

A detailed description of the error.

Remarks

The detailed description of the error is determined by the Win32 error message associated with the error.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Win32Exception(SerializationInfo, StreamingContext)

Source:
Win32Exception.cs
Source:
Win32Exception.cs
Source:
Win32Exception.cs

Caution

This API supports obsolete formatter-based serialization. It should not be called or extended by application code.

Initializes a new instance of the Win32Exception class with the specified context and the serialization information.

C#
[System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
protected Win32Exception(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
C#
protected Win32Exception(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);

Parameters

info
SerializationInfo

The SerializationInfo associated with this exception.

context
StreamingContext

A StreamingContext that represents the context of this exception.

Attributes

Applies to

.NET 10 and other versions
Product Versions (Obsolete)
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7 (8, 9, 10)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

Win32Exception(String, Exception)

Source:
Win32Exception.cs
Source:
Win32Exception.cs
Source:
Win32Exception.cs

Initializes a new instance of the Win32Exception class with the specified detailed description and the specified exception.

C#
public Win32Exception(string message, Exception innerException);
C#
public Win32Exception(string? message, Exception? innerException);

Parameters

message
String

A detailed description of the error.

innerException
Exception

A reference to the inner exception that is the cause of this exception.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0