[英]What exception type does C++ see when a C# class marked ComVisible throws an exception?
I have a C# class marked ComVisible that has a function that writes to a file. 我有一个标记为ComVisible的C#类,该类具有写入文件的功能。 If the folder the file is supposed to be written to does not exist, it throws a System.IO.DirectoryNotFoundException.
如果应该写入文件的文件夹不存在,则会引发System.IO.DirectoryNotFoundException。 If I use throw;
如果我使用throw; to raise it back to the C++ client, it doesn't get caught by any handler I know of except a generic (...) one.
将其提升回C ++客户端,除了通用(...),它不会被我知道的任何处理程序捕获。 What is the type of the exception object that the handler will get?
处理程序将获得的异常对象的类型是什么?
Here is the client method: 这是客户端方法:
void CRXReport::Export(CCOMString Destination)
{
CWaitCursor Wait;
// m_Report->Export("c:/misc/report2.pdf");
CCOMString message;
message << _T("Trying to export a report to ") << Destination;
AfxMessageBox(message);
if ( m_Report != NULL )
{
try
{
m_Report->Export(Destination.AllocSysString());
}
catch (CException& ex)
{
AfxMessageBox(_T("Failed to export the report; caught a CException reference."));
}
catch (CException* pEx)
{
AfxMessageBox(_T("Failed to export the report; caught a CException pointer."));
}
catch (_com_error* e)
{
AfxMessageBox(_T("Failed to export the report; caught a _com_error reference."));
}
catch (...)
{
AfxMessageBox(_T("Failed to export the report; caught something else."));
}
}
}
And, although I don't think it matters, here's the server method: 而且,尽管我认为这并不重要,但这是服务器方法:
public void Export(string destination)
{
LogOnToTables();
try
{
_report.ExportToDisk(ExportFormatType.PortableDocFormat, destination);
}
catch (Exception ex)
{
MessageBox.Show("Failed to export report: " + ex.Message);
throw;
}
}
The first comment contains the answer. 第一条评论包含答案。 I needed to catch a _com_error reference, not a pointer.
我需要捕获_com_error参考,而不是指针。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.