Win32Exception Classe
Definição
Gera uma exceção para um código de erro Win32.Throws an exception for a Win32 error code.
public ref class Win32Exception : Exception
public ref class Win32Exception : System::Runtime::InteropServices::ExternalException
public class Win32Exception : Exception
public class Win32Exception : System.Runtime.InteropServices.ExternalException
[System.Serializable]
public class Win32Exception : System.Runtime.InteropServices.ExternalException
type Win32Exception = class
inherit Exception
type Win32Exception = class
inherit ExternalException
interface ISerializable
[<System.Serializable>]
type Win32Exception = class
inherit ExternalException
interface ISerializable
Public Class Win32Exception
Inherits Exception
Public Class Win32Exception
Inherits ExternalException
- Herança
- Herança
- Derivado
- Atributos
- Implementações
Exemplos
O exemplo de código a seguir mostra como capturar uma exceção do Win32 e interpretar seu conteúdo.The following code example shows how to catch a Win32 exception and interpret its content. O exemplo tenta iniciar um executável inexistente, o que resulta em uma exceção Win32.The example attempts to start a nonexistent executable, which results in a Win32 exception. Após a captura da exceção, o exemplo busca a respectiva mensagem de erro, código e origem da exceção.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
Comentários
Os códigos de erro Win32 são convertidos de suas representações numéricas em uma mensagem do sistema quando são exibidos.Win32 error codes are translated from their numeric representations into a system message when they are displayed. Use NativeErrorCode para acessar a representação numérica do código de erro associado a essa exceção.Use NativeErrorCode to access the numeric representation of the error code associated with this exception. Para obter mais informações sobre os códigos de erro, consulte códigos de erro do Win32.For more information about the error codes, see Win32 Error Codes.
Construtores
| Win32Exception() |
Inicializa uma nova instância da classe Win32Exception com o último erro Win32 que ocorreu.Initializes a new instance of the Win32Exception class with the last Win32 error that occurred. |
| Win32Exception(Int32) |
Inicializa uma nova instância da classe Win32Exception com o erro especificado.Initializes a new instance of the Win32Exception class with the specified error. |
| Win32Exception(Int32, String) |
Inicializa uma nova instância da classe Win32Exception com o erro especificado e a descrição detalhada especificada.Initializes a new instance of the Win32Exception class with the specified error and the specified detailed description. |
| Win32Exception(SerializationInfo, StreamingContext) |
Inicializa uma nova instância da classe Win32Exception com o contexto e as informações de serialização especificados.Initializes a new instance of the Win32Exception class with the specified context and the serialization information. |
| Win32Exception(String) |
Inicializa uma nova instância da classe Win32Exception com a descrição detalhada especificada.Initializes a new instance of the Win32Exception class with the specified detailed description. |
| Win32Exception(String, Exception) |
Inicializa uma nova instância da classe Win32Exception com a descrição detalhada e a exceção especificadas.Initializes a new instance of the Win32Exception class with the specified detailed description and the specified exception. |
Propriedades
| Data |
Obtém uma coleção de pares de chave/valor que fornecem informações definidas pelo usuário adicionais sobre a exceção.Gets a collection of key/value pairs that provide additional user-defined information about the exception. (Herdado de Exception) |
| ErrorCode |
Obtém o |
| HelpLink |
Obtém ou define um link para o arquivo de ajuda associado a essa exceção.Gets or sets a link to the help file associated with this exception. (Herdado de Exception) |
| HResult |
Obtém ou define HRESULT, um valor numérico codificado que é atribuído a uma exceção específica.Gets or sets HRESULT, a coded numerical value that is assigned to a specific exception. (Herdado de Exception) |
| InnerException |
Obtém a instância Exception que causou a exceção atual.Gets the Exception instance that caused the current exception. (Herdado de Exception) |
| Message |
Obtém uma mensagem que descreve a exceção atual.Gets a message that describes the current exception. (Herdado de Exception) |
| NativeErrorCode |
Obtém o código de erro Win32 associado a essa exceção.Gets the Win32 error code associated with this exception. |
| Source |
Obtém ou define o nome do aplicativo ou objeto que causa o erro.Gets or sets the name of the application or the object that causes the error. (Herdado de Exception) |
| StackTrace |
Obtém uma representação de cadeia de caracteres de quadros imediatos na pilha de chamadas.Gets a string representation of the immediate frames on the call stack. (Herdado de Exception) |
| TargetSite |
Obtém o método que gerou a exceção atual.Gets the method that throws the current exception. (Herdado de Exception) |
Métodos
| Equals(Object) |
Determina se o objeto especificado é igual ao objeto atual.Determines whether the specified object is equal to the current object. (Herdado de Object) |
| GetBaseException() |
Quando substituído em uma classe derivada, retorna a Exception que é a causa raiz de uma ou mais exceções subsequentes.When overridden in a derived class, returns the Exception that is the root cause of one or more subsequent exceptions. (Herdado de Exception) |
| GetHashCode() |
Serve como a função de hash padrão.Serves as the default hash function. (Herdado de Object) |
| GetObjectData(SerializationInfo, StreamingContext) |
Define o objeto SerializationInfo com o nome do arquivo e número de linha em que essa Win32Exception ocorreu.Sets the SerializationInfo object with the file name and line number at which this Win32Exception occurred. |
| GetObjectData(SerializationInfo, StreamingContext) |
Quando substituído em uma classe derivada, define o SerializationInfo com informações sobre a exceção.When overridden in a derived class, sets the SerializationInfo with information about the exception. (Herdado de Exception) |
| GetType() |
Obtém o tipo de runtime da instância atual.Gets the runtime type of the current instance. (Herdado de Exception) |
| MemberwiseClone() |
Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object. (Herdado de Object) |
| ToString() |
Retorna uma cadeia de caracteres que contém NativeErrorCode ou HResult ou ambos.Returns a string that contains the NativeErrorCode, or HResult, or both. |
| ToString() |
Cria e retorna uma representação de cadeia de caracteres da exceção atual.Creates and returns a string representation of the current exception. (Herdado de Exception) |
| ToString() |
Retorna uma cadeia de caracteres que contém o HRESULT do erro.Returns a string that contains the HRESULT of the error. (Herdado de ExternalException) |
Eventos
| SerializeObjectState |
Ocorre quando uma exceção é serializada para criar um objeto de estado de exceção que contém dados serializados sobre a exceção.Occurs when an exception is serialized to create an exception state object that contains serialized data about the exception. (Herdado de Exception) |