2014-03-18 43 views
-2

雖然我纏着我的程序的每一個部分try代碼我不能讓這導致運行時錯誤(沒有任何其他細節)行:C++ - 「的std :: out_of_range」

"terminate called after throwing an instance of 'std::out_of_range' 
what(): vector::_M_range_check Aborted" 

,我不知道我應該做什麼。 該錯誤是由下面的代碼段引起的,因爲它似乎除了這些行之後:

..... 
map<int, StaticObject*>::iterator mapPos2; 
vector<StaticObject*, boost::pool_allocator<StaticObject*> >::iterator vecPos; 

map<int, int>::iterator mapPos = userCountMap.begin(); 

mapPos2 = this->_cachedObjects.find(this->_lruQueue.at(mapPos->first)->getId());     
vecPos = find(this->_lruQueue.begin(),this->_lruQueue.end(), this->_lruQueue.at(mapPos->first)); 

size -= this->_lruQueue.at(mapPos->first)->getSize(); 
_availableSpace += this->_lruQueue.at(mapPos->first)->getSize(); 

delete (*mapPos2).second; 

this->_cachedObjects.erase(mapPos2); 
this->_lruQueue.erase(vecPos); 
............ 

和稍後:

map<int, int> userCountMap; 

userCountMap.insert(make_pair(object->getId(),1)); ... 
this->userCountMap[id]++; ... 
this->userCountMap.clear(); .... 
+0

-1 WTH不清楚這個異常並跟蹤(調試)它拋出的點? –

回答

2

std::out_of_rangestd::vector::at拋出如果索引超出範圍的有效值(即[0..size-1])。

嘗試使用try/catch塊封裝調用該函數的行,並查看哪一個會拋出。然後,啓動調試器,找出索引超出範圍的原因。

相關問題