Einzelnen Beitrag anzeigen

Furtbichler
(Gast)

n/a Beiträge
 
#8

AW: Best Practice: Wann verwendet ihr Exceptions in Funktionen?

  Alt 10. Dez 2013, 16:38
Hathor hat da natürlich auch gerade eine Paradebeispiel für dieses Anti-Pattern geliefert.
Schnippeldi-Refaktor-DRY:
Delphi-Quellcode:
Procedure ReadNode (string title, nodeKey);
Begin
  try
      Nodes := XmlDoc.selectNodes(nodeKey);
      Form1.Memo1.lines.add(Format('%20s %s',[title,Nodes.Item(0).Text]));
  except
    on E:Exception do
      Form1.Memo1.lines.add(string,Format('---> %s not exists.',[title]);
  end;
End;
...
  ReadNode('1. SystemScore'     ,'//WinSAT/WinSPR/SystemScore');
  ReadNode('2. MemoryScore'     ,'//WinSAT/WinSPR/MemoryScore');
  ReadNode('3. CpuScore'        ,'//WinSAT/WinSPR/CpuScore');
  ReadNode('4. VideoEncodeScore','//WinSAT/WinSPR/VideoEncodeScore');
  ReadNode('5. GraphicsScore'   ,'//WinSAT/WinSPR/CpuScore');
  ReadNode('6. GamingScore'     ,'//WinSAT/WinSPR/GamingScore');
 ...
Ich kann mir nicht helfen: Eher ein Paradebeispiel, wie lesbar Code mit Exceptions wird (Und das ist noch nicht einmal gut refaktorisiert)
  Mit Zitat antworten Zitat