See https://github.com/bitcoin/bitcoin/pull/22762#issuecomment-951063826

This can be fixed by creating a new exception type and catching it in the right place.

#### Useful skills:

* C++ exceptions
* Addrman serialization
* Functional tests

#### Want to work on this issue?

For guidance on contributing, please read [CONTRIBUTING.md](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md) before opening your pull request.

{
    AssertLockHeld(cs);
    int nId = nIdCount++;
    mapInfo[nId] = AddrInfo(addr, addrSource);
    mapAddr[addr] = nId;
    mapInfo[nId].nRandomPos = vRandom.size();
    vRandom.push_back(nId);
    if (pnId)
        *pnId = nId;
    return &mapInfo[nId];
}
void AddrManImpl::SwapRandom(unsigned int nRndPos1, unsigned int nRndPos2) const
{
    AssertLockHeld(cs);
    if (nRndPos1 == nRndPos2)
        return;
    assert(nRndPos1 < vRandom.size() && nRndPos2 < vRandom.size());
    int nId1 = vRandom[nRndPos1];
    int nId2 = vRandom[nRndPos2];
    const auto it_1{mapInfo.find(nId1)};
    const auto it_2{mapInfo.find(nId2)};
    assert(it_1 != mapInfo.end());
    assert(it_2 != mapInfo.end());
    it_1->second.nRandomPos = nRndPos2;
    it_2->second.nRandomPos = nRndPos1;
    vRandom[nRndPos1] = nId2;
    vRandom[nRndPos2] = nId1;
}
void AddrManImpl::Delete(int nId)