anchor.diff:  //* Result: Group ID
   function TKMScriptStates.ClosestGroupEx(aPlayer, X, Y: Integer; aGroupType: TKMGroupType): Integer;
   begin
  -  Result := _ClosestGroup(aPlayer, X, Y, aGroupType, 'States.ClosestGroupEx');
  +  try
  +    Result := _ClosestGroup(aPlayer, X, Y, aGroupType, 'States.ClosestGroupEx');
  +  except
  +    gScriptEvents.ExceptionOutsideScript := True; //Don't blame script for this exception
  +    raise;
  +  end;
   end;
   
   
  
positive.code: procedure TKMScriptStates.AIGroupsFormationGet(aPlayer, aType: Byte; out aCount, aColumns: Integer);
  var
    gt: TKMGroupType;
  begin
    gt := gtNone;
  
    if InRange(aType, 0, 3) then
      gt := TKMGroupType(aType + GROUP_TYPE_MIN_OFF);
  
    _AIGroupsFormationGet(aPlayer, gt, aCount, aColumns, 'States.AIGroupsFormationGet');
  end;
  
  
  
negative.code:   GTS: TKMGroupTypeSet;
    G: TKMUnitGroup;
  begin
    Result := -1;
    if InRange(aPlayer, 0, gHands.Count - 1) and (gHands[aPlayer].Enabled)
      and gTerrain.TileInMapCoords(X, Y)
      and ((aGroupType = gtAny) or (aGroupType in GROUP_TYPES_VALID)) then
    begin
      if aGroupType = gtAny then
        GTS := GROUP_TYPES_VALID
      else
        GTS := [aGroupType];
  
      G := gHands[aPlayer].UnitGroups.GetClosestGroup(KMPoint(X,Y), GTS);
      if (G <> nil) and not G.IsDead then
      begin
        Result := G.UID;
        fIDCache.CacheGroup(G, G.UID);
      end;
    end
    else
      LogIntParamWarn(aMethodName, [aPlayer, X, Y, Ord(aGroupType)]);
  end;
  
  
  