UnhandledExceptionEventArgs.ExceptionObject Özellik
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
İşlenmeyen özel durum nesnesini alır.
public:
property System::Object ^ ExceptionObject { System::Object ^ get(); };
public object ExceptionObject { get; }
member this.ExceptionObject : obj
Public ReadOnly Property ExceptionObject As Object
Özellik Değeri
İşlenmeyen özel durum nesnesi.
Örnekler
Aşağıdaki örnekte olayı gösterilmektedir UnhandledException . Varsayılan uygulama etki alanında işlenmeyen bir özel durum oluştuğunda çağrılan bir olay işleyicisi MyHandlertanımlar. Ardından iki özel durum oluşturur. İlki bir try/catch bloğu tarafından işlenir. İkincisi işlenmemiştir ve uygulama sonlandırılmadan önce yordamı çağırır MyHandle .
using System;
public class Example
{
public static void Main()
{
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler);
try {
throw new Exception("1");
} catch (Exception e) {
Console.WriteLine("Catch clause caught : {0} \n", e.Message);
}
throw new Exception("2");
}
static void MyHandler(object sender, UnhandledExceptionEventArgs args)
{
Exception e = (Exception) args.ExceptionObject;
Console.WriteLine("MyHandler caught : " + e.Message);
Console.WriteLine("Runtime terminating: {0}", args.IsTerminating);
}
}
// The example displays the following output:
// Catch clause caught : 1
//
// MyHandler caught : 2
// Runtime terminating: True
//
// Unhandled Exception: System.Exception: 2
// at Example.Main()
open System
open System.Security.Permissions
let myHandler _ (args: UnhandledExceptionEventArgs) =
let e = args.ExceptionObject :?> Exception
printfn $"MyHandler caught : {e.Message}"
printfn $"Runtime terminating: {args.IsTerminating}"
[<EntryPoint>]
let main _ =
let currentDomain = AppDomain.CurrentDomain
currentDomain.UnhandledException.AddHandler(UnhandledExceptionEventHandler myHandler)
try
failwith "1"
with e ->
printfn $"Catch clause caught : {e.Message} \n"
failwith "2"
// The example displays the following output:
// Catch clause caught : 1
//
// MyHandler caught : 2
// Runtime terminating: True
//
// Unhandled Exception: System.Exception: 2
// at Example.main()
Module Example
Sub Main()
Dim currentDomain As AppDomain = AppDomain.CurrentDomain
AddHandler currentDomain.UnhandledException, AddressOf MyHandler
Try
Throw New Exception("1")
Catch e As Exception
Console.WriteLine("Catch clause caught : " + e.Message)
Console.WriteLine()
End Try
Throw New Exception("2")
End Sub
Sub MyHandler(sender As Object, args As UnhandledExceptionEventArgs)
Dim e As Exception = DirectCast(args.ExceptionObject, Exception)
Console.WriteLine("MyHandler caught : " + e.Message)
Console.WriteLine("Runtime terminating: {0}", args.IsTerminating)
End Sub
End Module
' The example displays the following output:
' Catch clause caught : 1
'
' MyHandler caught : 2
' Runtime terminating: True
'
' Unhandled Exception: System.Exception: 2
' at Example.Main()
Açıklamalar
Bu özellik, türünden ObjectExceptiontüretilmiş bir nesne değil, türünde bir nesne döndürür. Ortak Dil Belirtimi, tüm özel durum türlerinin 'den Exceptiontüretilmiş olmasını gerektirse de, yöntemlerin türünden Exceptiontüretilmemiş nesnelerle özel durumlar oluşturması mümkündür. Bu özel durumla çalışmak için aşağıdakileri yapabilirsiniz:
RuntimeCompatibilityAttribute değerini içeren RuntimeCompatibilityAttribute.WrapNonExceptionThrows
trueözniteliğini, olay işleyicisini içeren derlemeye uygulayın. Bu, bir RuntimeWrappedException nesnedeki sınıfından Exception türetilmeyen tüm özel durumları sarmalar. Daha sonra bu özellik tarafından döndürülen nesneyi güvenli bir Exception şekilde dönüştürebilir (C# dilinde) veya dönüştürebilir (Visual Basic'te) ve özelliğinden RuntimeWrappedException.WrappedException özgün özel durum nesnesini alabilirsiniz. C# ve Visual Basic derleyicileri gibi bazı derleyicilerin bu özniteliği otomatik olarak uyguladığını unutmayın.Bu özellik tarafından döndürülen nesneyi bir Exception nesneye yayın.