小编Rob*_*ger的帖子

使用unique_ptr离开范围时堆损坏

我遇到类似于函数堆损坏返回的void指针的问题

相似之处在于,当离开使用unique_ptr的作用域时,会收到“堆损坏”消息。

这里的代码:

void CMyClass::SomeMethod ()
{
  std::unique_ptr<IMyInterface> spMyInterface;
  spMyInterface.reset(new CMyInterfaceObject()); // CMyInterfaceObject is derived from IMyInterface

  any_list.push_back(spMyInterface.get()); // any_list: std::list<IMyInterface*>

  any_list.clear(); // only clears the pointers, but doesn't delete it

  // when leaving the scope, unique_ptr deletes the allocated objects... -> heap corruption
}
Run Code Online (Sandbox Code Playgroud)

知道为什么会这样吗?

c++ scope unique-ptr c++11

5
推荐指数
1
解决办法
1631
查看次数

无法捕获COMException(vb.net)

我使用以下代码访问VSS项目:

Dim sItem As String = "$/MyVssProject/InexistentFile.txt"
Dim oItem As SourceSafeTypeLib.VSSItem = Nothing
Try
  oItem = m_oSourceSafe.VSSItem(sItem)
Catch ex As Runtime.InteropServices.COMException
  MsgBox(ex.Message, MsgBoxStyle.Exclamation)
Catch ex As Exception
  MsgBox(ex.Message, MsgBoxStyle.Exclamation)
End Try
Run Code Online (Sandbox Code Playgroud)

我面临的问题是,当我尝试将实例获取到VSSDB中不存在的文件时,从而导致COMException,这基本上不会出现问题(我希望如此)。实际上,发生了异常,但是调试光标没有停留在捕获代码上,而是停留在“ oItem = m_oSourceSafe.VSSItem(sItem)”行上,显示标题为“ COMException越过本机/托管边界的对话框”。

从这里开始执行不会执行,直到我将sItem的内容更改为现有文件。

为什么未捕获到异常,如何实现?

环境:WinXP SP3 x86上带有.Net 2.0的VS2010

谢谢队友!

vb.net exception-handling visual-sourcesafe try-catch-finally vb.net-2010

3
推荐指数
1
解决办法
4593
查看次数