program Test_JclLastExceptStackList; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils, System.Classes, JclDebug, JclStrings; function IndexOfSubstring(aStrings: TStrings; const aSubstring: string): Integer; begin for var i := 0 to aStrings.Count - 1 do if aStrings[i].Contains(aSubstring) then Exit(i); Result := -1; end; function ContainsSubstringsInOrder(aStrings: TStrings; const aSubstrings: array of string): Boolean; begin if Length(aSubstrings) = 0 then Exit(True); var first := IndexOfSubstring(aStrings, aSubstrings[0]); if (first < 0) or (first + Length(aSubstrings) > aStrings.Count) then Exit(False); for var i := 1 to High(aSubstrings) do if not aStrings[first + i].Contains(aSubstrings[i]) then Exit(False); Result := True; end; procedure CheckLastExceptStackList(const aExpectedLines: array of string; const aUnexpectedLine: string = ''); begin var stackList := TStringList.Create; try JclLastExceptStackListToStrings(stackList, False, False, False, False); if not ContainsSubstringsInOrder(stackList, aExpectedLines) or ((aUnexpectedLine <> '') and (IndexOfSubstring(stackList, aUnexpectedLine) >= 0)) then begin Writeln('FAIL:'); Writeln(stackList.Text); end; finally stackList.Free; end; end; begin JclStartExceptionTracking; try FindClass(''); //"raise Exception.Create;" except CheckLastExceptStackList(['ClassNotFound', 'FindClass']); end; try TJclTabSet.FromString('['); //"raise;" except CheckLastExceptStackList(['ParseStops', 'FromString']); end; try var list := TList.Create; try list[-1]; //"raise ... at ReturnAddress;" finally list.Free; end; except CheckLastExceptStackList(['Get'], {unexpected:}'ListIndexError'); end; { Potential test cases: ErrorHandler in System.SysUtils.pas; SafeCallError in System.SysUtils.pas and System.Win.ComObj.pas; SignalConverter in System.Internal.ExcUtils.pas } Readln; end.