AggregateException Sınıf
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.
Uygulama yürütme sırasında oluşan bir veya daha fazla hatayı temsil eder.
public ref class AggregateException : Exception
public class AggregateException : Exception
[System.Serializable]
public class AggregateException : Exception
type AggregateException = class
inherit Exception
[<System.Serializable>]
type AggregateException = class
inherit Exception
Public Class AggregateException
Inherits Exception
- Devralma
- Öznitelikler
Örnekler
Aşağıdaki örnek özel durumu yakalar AggregateException ve içerdiği her özel durumu işlemek için yöntemini çağırır Handle . Örneği ilk task1 değişkenle derlemek ve çalıştırmak, özel durum içeren UnauthorizedAccessException bir AggregateException nesneyle sonuçlanmalıdır. Bu satırı açıklama satırına açıklama ekleme, ikinci task1 değişkenin açıklamasını kaldırma ve örneği derleyip çalıştırma, özel durum içeren bir AggregateExceptionIndexOutOfRangeException nesne oluşturur.
using System;
using System.IO;
using System.Threading.Tasks;
class Example
{
static async Task Main(string[] args)
{
// Get a folder path whose directories should throw an UnauthorizedAccessException.
string path = Directory.GetParent(
Environment.GetFolderPath(
Environment.SpecialFolder.UserProfile)).FullName;
// Use this line to throw UnauthorizedAccessException, which we handle.
Task<string[]> task1 = Task<string[]>.Factory.StartNew(() => GetAllFiles(path));
// Use this line to throw an exception that is not handled.
// Task task1 = Task.Factory.StartNew(() => { throw new IndexOutOfRangeException(); } );
try
{
await task1;
}
catch (UnauthorizedAccessException)
{
Console.WriteLine("Caught unauthorized access exception-await behavior");
}
catch (AggregateException ae)
{
Console.WriteLine("Caught aggregate exception-Task.Wait behavior");
ae.Handle((x) =>
{
if (x is UnauthorizedAccessException) // This we know how to handle.
{
Console.WriteLine("You do not have permission to access all folders in this path.");
Console.WriteLine("See your network administrator or try another path.");
return true;
}
return false; // Let anything else stop the application.
});
}
Console.WriteLine("task1 Status: {0}{1}", task1.IsCompleted ? "Completed," : "",
task1.Status);
}
static string[] GetAllFiles(string str)
{
// Should throw an UnauthorizedAccessException exception.
return System.IO.Directory.GetFiles(str, "*.txt", System.IO.SearchOption.AllDirectories);
}
}
// The example displays the following output if the file access task is run:
// You do not have permission to access all folders in this path.
// See your network administrator or try another path.
// task1 Status: Completed,Faulted
// It displays the following output if the second task is run:
// Unhandled Exception: System.AggregateException: One or more errors occurred. ---
// > System.IndexOutOfRangeException: Index was outside the bounds of the array.
// at Example.<Main>b__0()
// at System.Threading.Tasks.Task.Execute()
// --- End of inner exception stack trace ---
// at System.AggregateException.Handle(Func`2 predicate)
// at Example.Main(String[] args)
open System
open System.IO
open System.Threading.Tasks
let getAllFiles str =
// Should throw an UnauthorizedAccessException exception.
System.IO.Directory.GetFiles(str, "*.txt", System.IO.SearchOption.AllDirectories)
// Get a folder path whose directories should throw an UnauthorizedAccessException.
let path =
let directory =
Environment.SpecialFolder.UserProfile
|> Environment.GetFolderPath
|> Directory.GetParent
directory.FullName
// Use this line to throw an exception that is not handled.
// let task1 = Task<string []>.Factory.StartNew(fun () -> raise (IndexOutOfRangeException()) )
let task1 = Task.Factory.StartNew(fun () -> getAllFiles (path))
let execute () =
try
task1.Wait()
with
| :? UnauthorizedAccessException -> printfn "Caught unauthorized access exception-await behavior"
| :? AggregateException as ae ->
printfn "Caught aggregate exception-Task.Wait behavior"
ae.Handle (fun x ->
match x with
| :? UnauthorizedAccessException ->
printfn "You do not have permission to access all folders in this path."
printfn "See your network administrator or try another path."
true
| _ -> false)
printfn $"""task1 Status: {if task1.IsCompleted then "Completed," else ""}{task1.Status}"""
execute ()
// The example displays the following output if the file access task is run:
// You do not have permission to access all folders in this path.
// See your network administrator or try another path.
// task1 Status: Completed,Faulted
// It displays the following output if the second task is run:
// Unhandled exception. System.AggregateException: One or more errors occurred. (Index was outside the bounds of the array.) (Index was outside the bounds of the array.)
// ---> System.IndexOutOfRangeException: Index was outside the bounds of the array.
// at Exception1.task1@19.Invoke()
// at System.Threading.Tasks.Task`1.InnerInvoke()
// at System.Threading.Tasks.Task.<>c.<.cctor>b__277_0(Object obj)
// at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
// --- End of stack trace from previous location ---
// at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
// at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
// --- End of inner exception stack trace ---
// at System.AggregateException.Handle(Func`2 predicate)
// at <StartupCode$exception1>.$Exception1.main@()
Imports System.IO
Imports System.Threading.Tasks
Module Example
Sub Main()
' Get a folder path whose directories should throw an UnauthorizedAccessException.
Dim path As String = Directory.GetParent(
Environment.GetFolderPath(
Environment.SpecialFolder.UserProfile)).FullName
' Use this line to throw UnauthorizedAccessException, which we handle.
Dim task1 = Task(Of String()).Factory.StartNew(Function() GetAllFiles(path))
' Use this line to throw an exception that is not handled.
' Task task1 = Task.Factory.StartNew(Sub() Throw New IndexOutOfRangeException() )
Try
task1.Wait()
Catch ae As AggregateException
ae.Handle(Function(x)
If TypeOf (x) Is UnauthorizedAccessException Then ' This we know how to handle
Console.WriteLine("You do not have permission to access all folders in this path.")
Console.WriteLine("See your network administrator or try another path.")
Return True
Else
Return False ' Let anything else stop the application.
End If
End Function)
End Try
Console.WriteLine("task1 Status: {0}{1}", If(task1.IsCompleted, "Completed,", ""),
task1.Status)
End Sub
Function GetAllFiles(ByVal str As String) As String()
' Should throw an UnauthorizedAccessException exception.
Return System.IO.Directory.GetFiles(str, "*.txt", System.IO.SearchOption.AllDirectories)
End Function
End Module
Açıklamalar
AggregateException birden çok hatayı tek, atılabilir bir özel durum nesnesinde birleştirmek için kullanılır. Görev Paralel Kitaplığı (TPL) ve Paralel LINQ (PLINQ) içinde yaygın olarak kullanılır. Daha fazla bilgi için bkz. Özel Durum İşleme ve Nasıl yapılır: PLINQ Sorgusunda Özel Durumları İşleme. Daha fazla bilgi için, .NET Konuları blogunda Aggregating Exceptions girdisine bakın.
Oluşturucular
| Name | Description |
|---|---|
| AggregateException() |
hatayı açıklayan sistem tarafından sağlanan bir iletiyle AggregateException sınıfının yeni bir örneğini başlatır. |
| AggregateException(Exception[]) |
Bu özel durumun nedeni olan iç özel durumlara başvurularla sınıfının yeni bir örneğini AggregateException başlatır. |
| AggregateException(IEnumerable<Exception>) |
Bu özel durumun nedeni olan iç özel durumlara başvurularla sınıfının yeni bir örneğini AggregateException başlatır. |
| AggregateException(SerializationInfo, StreamingContext) |
Geçersiz.
Serileştirilmiş verilerle sınıfının yeni bir örneğini AggregateException başlatır. |
| AggregateException(String, Exception) |
Sınıfın AggregateException yeni bir örneğini belirtilen bir hata iletisiyle ve bu özel durumun nedeni olan iç özel duruma başvuruyla başlatır. |
| AggregateException(String, Exception[]) |
Sınıfın AggregateException yeni bir örneğini belirtilen bir hata iletisiyle başlatır ve bu özel durumun nedeni olan iç özel durumlara başvurur. |
| AggregateException(String, IEnumerable<Exception>) |
Sınıfın AggregateException yeni bir örneğini belirtilen bir hata iletisiyle başlatır ve bu özel durumun nedeni olan iç özel durumlara başvurur. |
| AggregateException(String) |
hatayı açıklayan belirtilen bir iletiyle AggregateException sınıfının yeni bir örneğini başlatır. |
Özellikler
| Name | Description |
|---|---|
| Data |
Özel durum hakkında kullanıcı tanımlı ek bilgiler sağlayan anahtar/değer çiftleri koleksiyonunu alır. (Devralındığı yer: Exception) |
| HelpLink |
Bu özel durumla ilişkili yardım dosyasının bağlantısını alır veya ayarlar. (Devralındığı yer: Exception) |
| HResult |
Belirli bir özel duruma atanan kodlanmış sayısal bir değer olan HRESULT değerini alır veya ayarlar. (Devralındığı yer: Exception) |
| InnerException |
Exception Geçerli özel duruma neden olan örneği alır. (Devralındığı yer: Exception) |
| InnerExceptions |
Geçerli özel duruma neden olan örneklerin Exception salt okunur bir koleksiyonunu alır. |
| Message |
Özel durumu açıklayan bir ileti alır. |
| Message |
Geçerli özel durumu açıklayan bir ileti alır. (Devralındığı yer: Exception) |
| Source |
Hataya neden olan uygulamanın veya nesnenin adını alır veya ayarlar. (Devralındığı yer: Exception) |
| StackTrace |
Çağrı yığınındaki anlık çerçevelerin dize gösterimini alır. (Devralındığı yer: Exception) |
| TargetSite |
Geçerli özel durumu oluşturan yöntemini alır. (Devralındığı yer: Exception) |
Yöntemler
| Name | Description |
|---|---|
| Equals(Object) |
Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler. (Devralındığı yer: Object) |
| Flatten() |
AggregateException Bir örneği tek, yeni bir örneğe düzleştirir. |
| GetBaseException() |
Exception Bu özel durumun kök nedenini döndürür. Bu özel durum, kök özel durumdur veya birden çok iç özel durum içeren veya iç özel durum içermeyen ilk AggregateException özel durumdur. |
| GetHashCode() |
Varsayılan karma işlevi işlevi görür. (Devralındığı yer: Object) |
| GetObjectData(SerializationInfo, StreamingContext) |
Geçersiz.
Serileştirilmiş verilerle sınıfının yeni bir örneğini AggregateException başlatır. |
| GetType() |
Geçerli örneğin çalışma zamanı türünü alır. (Devralındığı yer: Exception) |
| Handle(Func<Exception,Boolean>) |
Bu AggregateExceptiontarafından kapsanan her Exception üzerinde bir işleyici çağırır. |
| MemberwiseClone() |
Geçerli Objectbasit bir kopyasını oluşturur. (Devralındığı yer: Object) |
| ToString() |
Geçerli AggregateExceptionöğesinin dize gösterimini oluşturur ve döndürür. |
Ekinlikler
| Name | Description |
|---|---|
| SerializeObjectState |
Geçersiz.
Özel durum hakkında serileştirilmiş veriler içeren bir özel durum durumu nesnesi oluşturmak için bir özel durum seri hale getirildiğinde gerçekleşir. (Devralındığı yer: Exception) |
Şunlara uygulanır
İş Parçacığı Güvenliği
tüm genel ve korumalı üyeleri AggregateException iş parçacığı açısından güvenlidir ve birden çok iş parçacığından eşzamanlı olarak kullanılabilir.