Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Algorithmen, Datenstrukturen und Klassendesign (https://www.delphipraxis.net/78-algorithmen-datenstrukturen-und-klassendesign/)
-   -   EAggregateException (https://www.delphipraxis.net/196202-eaggregateexception.html)

Der schöne Günther 1. Mai 2018 09:18

EAggregateException
 
Da keine Dokumentation zu System.Threading.EAggregateException existiert gehe ich einmal davon aus dass man sich an .NET's System.AggregateException orientiert hat und lese als Ersatz dessen Doku:

Zitat:

AggregateException is used to consolidate multiple failures into a single, throwable exception object. It is used extensively in the Task Parallel Library (TPL) and Parallel LINQ (PLINQ). For additional information, see the Aggregating Exceptions entry in the .NET Matters blog.
Meine Zwei Fragen:
  1. Auch wenn es in System.Threading steckt hat es nicht zwangsläufig mit Threads/Tasks zu tun. Ich "darf" es auch als Ergebnis von normaler, serieller Abarbeitung nehmen, richtig?
  2. Angenommen mehrere Durchgänge einer for-Schleife schlagen fehl und ich möchte das in Form einer
    Delphi-Quellcode:
    EAggregateException
    nach oben hin kenntlich machen. Ist das im Folgenden so ok?

Delphi-Quellcode:
uses System.Threading;

procedure processData(const input: Integer);
begin
   if Odd(input) then
      raise EProgrammerNotFound.CreateFmt('Error while processing "%d"', [input]);
end;

procedure doStuff();
var
   exceptions: TArray<Exception>;
   i: Integer;
begin
   exceptions := [];
   for i := 0 to 5 do
      try
         processData(i);
      except
         exceptions := exceptions + [Exception(AcquireExceptionObject())];
         Continue;
      end;

   case Length(exceptions) of
      0: Exit;
      1: raise exceptions[0];
   else
      raise EAggregateException.Create('Calculations failed', exceptions);
   end;
end;

dummzeuch 1. Mai 2018 09:54

AW: EAggregateException
 
Die "Doku" zu EAggregateException ist ja echt ziemlich peinlich. Vermutlich hat Embarcadero inzwischen vergessen, dass es die gar nicht gibt.

So, wie ich den Code verstehe, hast Du recht: Es spricht absolut nicths dagegen, sie so zu verwenden, wie in Deinem Beispiel. Man braucht dann natürlich auch einen sinnvollen Exception-Handler dafür.


Alle Zeitangaben in WEZ +1. Es ist jetzt 16:27 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz