Exception handling 如何在Visual Studio 2015中捕获此异常?

Exception handling 如何在Visual Studio 2015中捕获此异常?,exception-handling,mfc,indexoutofboundsexception,Exception Handling,Mfc,Indexoutofboundsexception,我在申请中遇到了这个问题。点击调试按钮可提供以下详细信息: Exception thrown: write access violation. std::map<ATL::CStringT<wchar_t,StrTraitMFC<wchar_t,ATL::ChTraitsCRT<wchar_t> > >,bool [52],std::less<ATL::CStringT<wchar_t,StrTraitMFC<wchar_t,ATL:

我在申请中遇到了这个问题。点击调试按钮可提供以下详细信息:

Exception thrown: write access violation.

std::map<ATL::CStringT<wchar_t,StrTraitMFC<wchar_t,ATL::ChTraitsCRT<wchar_t> > >,bool [52],std::less<ATL::CStringT<wchar_t,StrTraitMFC<wchar_t,ATL::ChTraitsCRT<wchar_t> > > >,std::allocator<std::pair<ATL::CStringT<wchar_t,StrTraitMFC<wchar_t,ATL::ChTraitsCRT<wchar_t> > > const ,bool [52]> > >::operator[](...) was 0x111026CE50857E9.

If there is a handler for this exception, the program may be safely continued.
该变量的定义:

const int kMaxStudyPointCount = 52;
typedef map<CString, bool[kMaxStudyPointCount]> AssignedStudyPoints;    
AssignedStudyPoints m_mapStudentAssignedStudyPoints;
const int kMaxStudyPointCount=52;
指定学习点的类型定义图;
指定学习点m_mapStudentAssignedStudyPoints;
我想给你一个示例应用程序,但它是一个巨大的应用程序。在我看来,它在[]任务中失败了

我做了更多的调查,iStudyPoint被设置为65535(我理解为-1)。我的布尔数组限制为0-51,所以我对它的断言并不感到惊讶


我现在已经解决了代码中出现65535的根本原因。但是,我的问题是,我应该使用哪种类型的try/catch语句,以便在分配地图条目内容时捕捉此类问题?

您是否调查了异常发生之前发生的情况?也许,
iStudyPoint
已经是65535了。尝试放置一个
断言(iStudyPoint>=0&&iStudyPoint)。我发现确实如此。然后从一开始就解决了这个问题。但是当您分配一个越界索引时,如何捕获?断言只在调试中起作用,不是吗?进行一些单元测试怎么样?@rrirower什么意思?我现在在applic的其他地方测试单元值序列化(从磁盘序列化源数据)。我正在询问我需要捕获哪些异常以检测越界。谢谢。如果您使用类似的方法,您可能能够阻止任何潜在问题。您是否调查了异常发生之前发生的情况?可能
iStudyPoint
已经是65535。尝试放置
断言(iStudyPoint>=0&&iStudyPoint)。我发现确实如此。然后从一开始就解决了这个问题。但是当您分配一个越界索引时,如何捕获?断言只在调试中起作用,不是吗?进行一些单元测试怎么样?@rrirower什么意思?我现在在applic的其他地方测试单元值序列化(从磁盘序列化源数据)。我在问我需要捕获什么异常以检测越界。谢谢。如果您使用类似的方法,您可能可以避免任何潜在问题。
const int kMaxStudyPointCount = 52;
typedef map<CString, bool[kMaxStudyPointCount]> AssignedStudyPoints;    
AssignedStudyPoints m_mapStudentAssignedStudyPoints;