C++ Visual Studio 2013 Unwinding object
C++ Visual Studio 2013 Unwinding object
嗯,我正试图构建这行代码,但我得到一个编译器错误。我试过在没有编译器的情况下构建,但这也不起作用。是关于__try
和__except
的。有人告诉我把try块中的代码移到另一个函数中。但是我不明白这个:
错误12:不能在函数中使用__try对象解除
输入文件
void MSocketThread::Run()
{
__try{
//throw(pThread);
while (true) { // Waiting for SafeUDP Settting...
DWORD dwVal = WaitForSingleObject(m_KillEvent.GetEvent(), 100);
if (dwVal == WAIT_OBJECT_0) {
return;
}
else if (dwVal == WAIT_TIMEOUT) {
if (m_pSafeUDP)
break;
}
}
WSAEVENT EventArray[WSA_MAXIMUM_WAIT_EVENTS];
WORD wEventIndex = 0;
bool bSendable = false;
WSANETWORKEVENTS NetEvent;
WSAEVENT hFDEvent = WSACreateEvent();
EventArray[wEventIndex++] = hFDEvent;
EventArray[wEventIndex++] = m_ACKEvent.GetEvent();
EventArray[wEventIndex++] = m_SendEvent.GetEvent();
EventArray[wEventIndex++] = m_KillEvent.GetEvent();
WSAEventSelect(m_pSafeUDP->GetLocalSocket(), hFDEvent, FD_READ | FD_WRITE);
while (TRUE) {
DWORD dwReturn = WSAWaitForMultipleEvents(wEventIndex, EventArray, FALSE, SAFEUDP_SAFE_MANAGE_TIME, FALSE);
if (dwReturn == WSA_WAIT_TIMEOUT) { // Time
m_pSafeUDP->LockNetLink();
SafeSendManage();
m_pSafeUDP->UnlockNetLink();
}
else if (dwReturn == WSA_WAIT_EVENT_0) { // Socket Event
WSAEnumNetworkEvents(m_pSafeUDP->GetLocalSocket(), hFDEvent, &NetEvent);
if ((NetEvent.lNetworkEvents & FD_READ) == FD_READ) {
// OutputDebugString("SUDP> FD_READ n");
m_pSafeUDP->LockNetLink();
Recv();
m_pSafeUDP->UnlockNetLink();
}
if ((NetEvent.lNetworkEvents & FD_WRITE) == FD_WRITE) {
bSendable = true;
// OutputDebugString("SUDP> FD_WRITE n");
}
}
else if (dwReturn == WSA_WAIT_EVENT_0 + 1) { // ACK Send Event
// OutputDebugString("SUDP> ACK_EVENT n");
FlushACK();
}
else if (dwReturn == WSA_WAIT_EVENT_0 + 2) { // Packet Send Event
// OutputDebugString("SUDP> SEND_EVENT n");
if (bSendable == true)
FlushSend();
}
else if (dwReturn == WSA_WAIT_EVENT_0 + 3) { // Kill the Thread
break; // Stop Thread
}
}
WSACloseEvent(hFDEvent);
// Clear Queues
LockSend();
{
for (SendListItor itor = m_SendList.begin(); itor != m_SendList.end();) {
delete (*itor);
itor = m_SendList.erase(itor);
}
}
{
for (SendListItor itor = m_TempSendList.begin(); itor != m_TempSendList.end();) {
delete (*itor);
itor = m_TempSendList.erase(itor);
}
}
UnlockSend();
LockACK();
{
for (ACKSendListItor itor = m_ACKSendList.begin(); itor != m_ACKSendList.end();) {
delete (*itor);
itor = m_ACKSendList.erase(itor);
}
}
{
for (ACKSendListItor itor = m_TempACKSendList.begin(); itor != m_TempACKSendList.end();) {
delete (*itor);
itor = m_TempACKSendList.erase(itor);
}
}
UnlockACK();
}
__except (this->CrashDump(GetExceptionInformation()))
基本上,SEH和c++展开并不完全兼容;它们要求编译器在机器码级别修改函数,而MS显然决定不同时支持对两者的修改,因此任何函数只能支持SEH unwind动作(__except或__finally)或c++ unwind动作(catch或带有析构函数的对象)。
我怀疑你的问题出在循环中的迭代器上;它们可能有析构函数。虽然迭代器通常很简单,不需要析构函数,但调试迭代器却不是这样,调试迭代器通常在构造时注册它们的存在,在析构时取消注册,以便检测无效的迭代器和其他无效的用法。
通常的解决方法是拆分函数。让你的run函数只包含以下内容:
void MSocketThread::Run()
{
__try {
RunNoSeh();
} __except (this->CrashDump(GetExceptionInformation())) {
}
}
void MSocketThread::RunNoSeh()
{
// Code that was inside the __try goes here.
}
相关文章:
- 当覆盖存在时调用基本虚拟"binded to object"函数
- "Unable to start debugging. No process is associated with this object." - 在Visual Studio Code中使用GDB
- C++将派生类转换为基类时'object slicing'期间发生的情况
- 如何理解 C++17 标准参考中的 [intro.object]/3? N4659 的
- "Cannot convert Python object argument to type '<typename>'" - 使用 Cython 包装 C++ 类时出错
- 使用 object 中的方法调用带有 std::bind 和 std::function.target 的 C 样式函数
- "Called Object Type is Not a Function or Pointer" 与 typedef 和类
- C++线程"Call to non-static member function without an object argument"
- dopen():不以 root 身份运行时"failed to map segment from shared object"
- 当两个成员位于同一类中时出错"a nonstatic member reference must be relative to a specific object"
- Nan::ObjectWrap to Napi::Object Wrap 无法访问 JavaScript 中的属性
- 现代C++会支持 C# "Object Initalizer"语法吗?
- 指向对象生存期之外的已分配内存的指针是"invalid pointer[s]"还是"pointer[s] to an object"?
- C++ Equivalent of Java Map<String, Object>
- WebKit2GTK+ "window-object-cleared"未清除
- 返回 *&object 时是否允许复制/移动省略?
- QPointer::clear() 是删除其引用的指针,还是"Clears this QPointer object."其他含义?
- 解决方法:'can not be used when making a shared object; recompile with -fPIC'使用Cmake。使用普通的 g++ 工作
- 根据标准,究竟什么是"declaration of an object"
- C++ Visual Studio 2013 Unwinding object