简体   繁体   English

C ++通过DLL向C#抛出错误

[英]C++ throwing error through dll to c#

I created C++ Dll 我创建了C ++ Dll

Initialize()
{
if(!_fs.isOpened())
    {
        throw ERROR_FILE_NOT_FOUND;
        _logfile << "Error ! Opening BDS.xml" << "\t" <<_arrivalTime<<endl;
        _logfile.close();
    }
}

and calling this function in C# 并在C#中调用此函数

private void button1_Click(object sender, EventArgs e)
{
    try
    {
        Initialize();
    }
    catch (RuntimeWrappedException ex)
    {
        MessageBox.Show(ex.Message);
    }
}

But I am getting this error SEHException was Unhandled External Component has thrown an exception I tried C# all exception method but i did not get the correct answer. 但是我收到此错误SEHException是Unhandled External Component引发了异常,我尝试了C#所有异常方法,但没有得到正确的答案。 Can some One please help me?Or tell me how to throw exception from C++ Dll and Catch same Exception in C# and wait for response of C#. 有人可以帮我吗?或者告诉我如何从C ++ Dll引发异常并在C#中捕获相同的异常,然后等待C#的响应。 Like Retry, Abort, Ignore error, if Retry pressed than it again starts opening the file in Dll. 像重试,中止,忽略错误一样,如果按重试键,它将再次开始在Dll中打开文件。 how should i do this . 我该怎么做。 please help me out of this. 请帮助我。

It is C++\\CLI not C++ exception. 这是C ++ \\ CLI而不是C ++异常。 In C++\\CLI, do the following: 在C ++ \\ CLI中,执行以下操作:

 throw gcnew System::Exception("It is a C++\CLI exception");

rather than c++ native exception 而不是c ++本机异常

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM