Win32Exception Win32Exception Win32Exception Win32Exception Class

定义

针对 Win32 错误代码引发异常。Throws an exception for a Win32 error code.

public ref class Win32Exception : System::Runtime::InteropServices::ExternalException
[System.Serializable]
public class Win32Exception : System.Runtime.InteropServices.ExternalException
type Win32Exception = class
    inherit ExternalException
    interface ISerializable
Public Class Win32Exception
Inherits ExternalException
继承
派生
属性
实现

示例

下面的代码示例演示如何捕获 Win32 异常并解释其内容。The following code example shows how to catch a Win32 exception and interpret its content. 该示例尝试启动不存在的可执行文件, 从而导致 Win32 异常。The example attempts to start a nonexistent executable, which results in a Win32 exception. 捕获异常时, 此示例将提取相应的错误消息、代码和异常的源。Upon catching the exception, the example fetches the respective error message, code, and origin of the exception.

try
{
   System::Diagnostics::Process^ myProc = gcnew System::Diagnostics::Process;
   //Attempting to start a non-existing executable
   myProc->StartInfo->FileName = "c:\nonexist.exe";
   //Start the application and assign it to the process component.
   myProc->Start();
}
catch ( Win32Exception^ w ) 
{
   Console::WriteLine( w->Message );
   Console::WriteLine( w->ErrorCode );
   Console::WriteLine( w->NativeErrorCode );
   Console::WriteLine( w->StackTrace );
   Console::WriteLine( w->Source );
   Exception^ e = w->GetBaseException();
   Console::WriteLine( e->Message );
}
   try {
System.Diagnostics.Process myProc = new System.Diagnostics.Process();
myProc.StartInfo.FileName = "c:\nonexist.exe";  //Attempting to start a non-existing executable
myProc.Start();    //Start the application and assign it to the process component.    
   }
	    catch(Win32Exception w) {
Console.WriteLine(w.Message);
Console.WriteLine(w.ErrorCode.ToString());
Console.WriteLine(w.NativeErrorCode.ToString());
Console.WriteLine(w.StackTrace);
Console.WriteLine(w.Source);
Exception e=w.GetBaseException();
Console.WriteLine(e.Message);
    }
Try
    Dim myProc As New System.Diagnostics.Process()
    myProc.StartInfo.FileName = "c:\nonexist.exe"  'Attempting to start a non-existing executable
    myProc.Start()    'Start the application and assign it to the process component.    

Catch w As System.ComponentModel.Win32Exception
    Console.WriteLine(w.Message)
    Console.WriteLine(w.ErrorCode.ToString())
    Console.WriteLine(w.NativeErrorCode.ToString())
    Console.WriteLine(w.StackTrace)
    Console.WriteLine(w.Source)
    Dim e As New Exception()
    e = w.GetBaseException()
    Console.WriteLine(e.Message)
End Try

注解

在显示时,Win32 错误代码被从数值表示形式转换为系统消息。Win32 error codes are translated from their numeric representations into a system message when they are displayed. 使用NativeErrorCode可访问与此异常相关联的错误代码的数值表示形式。Use NativeErrorCode to access the numeric representation of the error code associated with this exception. 有关错误代码的详细信息, 请参阅中平台 SDK 文档http://msdn.microsoft.com中的 "Win32 错误代码"。For more information about the error codes, see "Win32 Error Codes" in the Platform SDK documentation at http://msdn.microsoft.com.

构造函数

Win32Exception() Win32Exception() Win32Exception() Win32Exception()

使用出现的最后一个 Win32 错误初始化 Win32Exception 类的新实例。Initializes a new instance of the Win32Exception class with the last Win32 error that occurred.

Win32Exception(Int32) Win32Exception(Int32) Win32Exception(Int32) Win32Exception(Int32)

使用指定错误初始化 Win32Exception 类的新实例。Initializes a new instance of the Win32Exception class with the specified error.

Win32Exception(Int32, String) Win32Exception(Int32, String) Win32Exception(Int32, String) Win32Exception(Int32, String)

使用指定错误和指定的详细说明初始化 Win32Exception 类的新实例。Initializes a new instance of the Win32Exception class with the specified error and the specified detailed description.

Win32Exception(SerializationInfo, StreamingContext) Win32Exception(SerializationInfo, StreamingContext) Win32Exception(SerializationInfo, StreamingContext) Win32Exception(SerializationInfo, StreamingContext)

用指定的上下文和序列化信息初始化 Win32Exception 类的新实例。Initializes a new instance of the Win32Exception class with the specified context and the serialization information.

Win32Exception(String) Win32Exception(String) Win32Exception(String) Win32Exception(String)

使用指定的详细说明初始化 Win32Exception 类的新实例。Initializes a new instance of the Win32Exception class with the specified detailed description.

Win32Exception(String, Exception) Win32Exception(String, Exception) Win32Exception(String, Exception) Win32Exception(String, Exception)

使用指定的详细说明和指定的异常初始化 Win32Exception 类的新实例。Initializes a new instance of the Win32Exception class with the specified detailed description and the specified exception.

属性

Data Data Data Data

获取提供有关异常的其他用户定义信息的键/值对集合。Gets a collection of key/value pairs that provide additional user-defined information about the exception.

(Inherited from Exception)
ErrorCode ErrorCode ErrorCode ErrorCode

获取错误的 HRESULTGets the HRESULT of the error.

(Inherited from ExternalException)
HelpLink HelpLink HelpLink HelpLink

获取或设置指向与此异常关联的帮助文件链接。Gets or sets a link to the help file associated with this exception.

(Inherited from Exception)
HResult HResult HResult HResult

获取或设置 HRESULT(一个分配给特定异常的编码数字值)。Gets or sets HRESULT, a coded numerical value that is assigned to a specific exception.

(Inherited from Exception)
InnerException InnerException InnerException InnerException

获取导致当前异常的 Exception 实例。Gets the Exception instance that caused the current exception.

(Inherited from Exception)
Message Message Message Message

获取描述当前异常的消息。Gets a message that describes the current exception.

(Inherited from Exception)
NativeErrorCode NativeErrorCode NativeErrorCode NativeErrorCode

获取与此异常关联的 Win32 错误代码。Gets the Win32 error code associated with this exception.

Source Source Source Source

获取或设置导致错误的应用程序或对象的名称。Gets or sets the name of the application or the object that causes the error.

(Inherited from Exception)
StackTrace StackTrace StackTrace StackTrace

获取调用堆栈上的即时框架字符串表示形式。Gets a string representation of the immediate frames on the call stack.

(Inherited from Exception)
TargetSite TargetSite TargetSite TargetSite

获取引发当前异常的方法。Gets the method that throws the current exception.

(Inherited from Exception)

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetBaseException() GetBaseException() GetBaseException() GetBaseException()

当在派生类中重写时,返回 Exception,它是一个或多个并发的异常的根源。When overridden in a derived class, returns the Exception that is the root cause of one or more subsequent exceptions.

(Inherited from Exception)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext)

使用发生此 SerializationInfo 的文件名和行号设置 Win32Exception 对象。Sets the SerializationInfo object with the file name and line number at which this Win32Exception occurred.

GetType() GetType() GetType() GetType()

获取当前实例的运行时类型。Gets the runtime type of the current instance.

(Inherited from Exception)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

返回包含 NativeErrorCode 和/或 HResult 的字符串。Returns a string that contains the NativeErrorCode, or HResult, or both.

事件

SerializeObjectState SerializeObjectState SerializeObjectState SerializeObjectState

当异常被序列化用来创建包含有关该异常的徐列出数据的异常状态对象时会出现该问题。Occurs when an exception is serialized to create an exception state object that contains serialized data about the exception.

(Inherited from Exception)

适用于