Win32Exception Klass

Definition

Utlöser ett undantag för en Win32-felkod.

public ref class Win32Exception : Exception
public ref class Win32Exception : System::Runtime::InteropServices::ExternalException
public class Win32Exception : Exception
[System.Serializable]
public class Win32Exception : System.Runtime.InteropServices.ExternalException
public class Win32Exception : System.Runtime.InteropServices.ExternalException
type Win32Exception = class
    inherit Exception
[<System.Serializable>]
type Win32Exception = class
    inherit ExternalException
    interface ISerializable
type Win32Exception = class
    inherit ExternalException
    interface ISerializable
Public Class Win32Exception
Inherits Exception
Public Class Win32Exception
Inherits ExternalException
Arv
Win32Exception
Arv
Härledda
Attribut
Implementeringar

Exempel

Följande kodexempel visar hur du fångar ett Win32-undantag och tolkar dess innehåll. Exemplet försöker starta en icke-existerande körbar fil, vilket resulterar i ett Win32-undantag. När undantaget fångas hämtar exemplet respektive felmeddelande, kod och ursprung för undantaget.

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();
    myProc.StartInfo.FileName = @"c:\nonexist.exe"; // Attempt to start a non-existent executable
    _ = myProc.Start();
}
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

Kommentarer

Win32-felkoder översätts från deras numeriska representationer till ett systemmeddelande när de visas. Använd NativeErrorCode för att komma åt den numeriska representationen av felkoden som är associerad med det här undantaget. Mer information om felkoderna finns i Win32-felkoder.

Konstruktorer

Name Description
Win32Exception()

Initierar en ny instans av Win32Exception klassen med det senaste Win32-felet som inträffade.

Win32Exception(Int32, String)

Initierar en ny instans av Win32Exception klassen med det angivna felet och den angivna detaljerade beskrivningen.

Win32Exception(Int32)

Initierar en ny instans av Win32Exception klassen med det angivna felet.

Win32Exception(SerializationInfo, StreamingContext)

Initierar en ny instans av Win32Exception klassen med den angivna kontexten och serialiseringsinformationen.

Win32Exception(String, Exception)

Initierar en ny instans av Win32Exception klassen med den angivna detaljerade beskrivningen och det angivna undantaget.

Win32Exception(String)

Initierar en ny instans av Win32Exception klassen med den angivna detaljerade beskrivningen.

Egenskaper

Name Description
Data

Hämtar en samling nyckel/värde-par som ger ytterligare användardefinierad information om undantaget.

(Ärvd från Exception)
ErrorCode

HRESULT Hämtar felet.

(Ärvd från ExternalException)
HelpLink

Hämtar eller anger en länk till hjälpfilen som är associerad med det här undantaget.

(Ärvd från Exception)
HResult

Hämtar eller anger HRESULT, ett kodat numeriskt värde som har tilldelats ett specifikt undantag.

(Ärvd från Exception)
InnerException

Hämtar den Exception instans som orsakade det aktuella undantaget.

(Ärvd från Exception)
Message

Hämtar ett meddelande som beskriver det aktuella undantaget.

(Ärvd från Exception)
NativeErrorCode

Hämtar Win32-felkoden som är associerad med det här undantaget.

Source

Hämtar eller anger namnet på programmet eller objektet som orsakar felet.

(Ärvd från Exception)
StackTrace

Hämtar en strängrepresentation av de omedelbara ramarna i anropsstacken.

(Ärvd från Exception)
TargetSite

Hämtar den metod som utlöser det aktuella undantaget.

(Ärvd från Exception)

Metoder

Name Description
Equals(Object)

Avgör om det angivna objektet är lika med det aktuella objektet.

(Ärvd från Object)
GetBaseException()

När den åsidosätts i en härledd klass returnerar den Exception som är rotorsaken till ett eller flera efterföljande undantag.

(Ärvd från Exception)
GetHashCode()

Fungerar som standard-hash-funktion.

(Ärvd från Object)
GetObjectData(SerializationInfo, StreamingContext)

Anger objektet SerializationInfo med filnamnet och radnumret där detta Win32Exception inträffade.

GetType()

Hämtar körningstypen för den aktuella instansen.

(Ärvd från Exception)
MemberwiseClone()

Skapar en ytlig kopia av den aktuella Object.

(Ärvd från Object)
ToString()

Returnerar en sträng som innehåller NativeErrorCode, eller HResult, eller båda.

ToString()

Skapar och returnerar en strängrepresentation av det aktuella undantaget.

(Ärvd från Exception)
ToString()

Returnerar en sträng som innehåller HRESULT för felet.

(Ärvd från ExternalException)

Händelser

Name Description
SerializeObjectState

Inträffar när ett undantag serialiseras för att skapa ett undantagstillståndsobjekt som innehåller serialiserade data om undantaget.

(Ärvd från Exception)

Gäller för