# Why am I getting exception 0x80000003 when iterating over a set?

**URL:** <https://forums.unrealengine.com/t/why-am-i-getting-exception-0x80000003-when-iterating-over-a-set/490670>\
**Category:** C++\
**Tags:** exception, unreal-engine, question, CPP\
**Created:** [November 6, 2021, 9:24pm UTC](https://forums.unrealengine.com/t/why-am-i-getting-exception-0x80000003-when-iterating-over-a-set/490670 "2021-11-06T21:24:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guy\_Paddock](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Guy\_Paddock](https://forums.unrealengine.com/u/Guy_Paddock)\
**Post date:** [November 6, 2021, 9:24pm UTC](https://forums.unrealengine.com/t/why-am-i-getting-exception-0x80000003-when-iterating-over-a-set/490670/1 "2021-11-06T21:24:51Z")

</div>

I have code that looks like this:

```
for (const FName& ActiveGroup : this->ActivatedWeightGroups)
{
	if (StartingWeightGroup.LexicalLess(ActiveGroup) && this->DeactivatePassiveGameplayEffects(ActiveGroup))
	{
		DeactivatedGroups.Add(ActiveGroup);
		this->ActivatedWeightGroups.Remove(ActiveGroup);
	}
}

```

For some reason, every time I run this code I get a very cryptic exception (0x80000003) in the debugger on the `for` line. Why? What causes this?

---

<div class="post-metadata">

**Author:** ![Guy\_Paddock](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Guy\_Paddock](https://forums.unrealengine.com/u/Guy_Paddock)\
**Post date:** [November 6, 2021, 9:25pm UTC](https://forums.unrealengine.com/t/why-am-i-getting-exception-0x80000003-when-iterating-over-a-set/490670/2 "2021-11-06T21:25:52Z")

</div>

The issue here was that I was modifying the set while iterating over it, so the exception appears to have been that the code was reading data past the end of the set.

---

<div class="post-metadata">

**Author:** ![TimLewis](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TimLewis](https://forums.unrealengine.com/u/TimLewis)\
**Post date:** [May 12, 2022, 8:29pm UTC](https://forums.unrealengine.com/t/why-am-i-getting-exception-0x80000003-when-iterating-over-a-set/490670/3 "2022-05-12T20:29:13Z")

</div>

For anyone interested in how to remove items while iterating over a for loop, it’s advised you iterate in reverse.

```auto
for(int i = size - 1; i >= 0; i--)
{
// Remove index here
}

```
