Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all.

I'm using the C++/CLI dll on the C# WinForm project.
To pass from the native code's exception message to C#, I have written the code as below.

#include "pch.h"
#include "ClassLibrary1.h"

using namespace ClassLibrary1;

void Class1::ThrowMessage()
{
	try
	{
		throw std::exception("Throw message");
		//SEHException message occurred!
	}
	catch (const std::exception& exc)
	{
		throw gcnew System::Exception(msclr::interop::marshal_as<System::String^>(exc.what()));
	}
}


The program works well.
But the 'System.Runtime.InteropServices.SEHException'(ClassLibrary1.dll) message is shown in the Visual Studio's output window.

If I check the SEHException option in the Visual Studio's Exception Option window, I could see the System.Runtime.InteropServices.SEHException: 'External component has thrown an exception.' message.

Is it ok to ignore this message?
If not, what should I do?

Here is my short sample code.
https://bigfile-0002.cafe24.com/down.php?fileKey=133bc2625594b537c28e4e28563b9fbf[^]

Please somebody help me.

Thank you.

What I have tried:

I looked through several sites through a search, but couldn't find a solution.
Posted
Comments
Richard MacCutchan 29-Jun-22 3:20am    
It is your code that is throwing the exception.
code_pop 29-Jun-22 19:54pm    
Yes, right. I threw the std::exception in the managed code.
My question is "the SEHException has occurred when throwing the unmanaged code's exception in the managed code".
I read Microsoft's article, but I don't know how to do it properly.
https://docs.microsoft.com/en-us/cpp/dotnet/exceptions-in-cpp-cli?view=msvc-170
Richard MacCutchan 30-Jun-22 5:18am    
You are throwing the exception so you are the only person who knows a) why it has been thrown, and b) what to do about it.
code_pop 30-Jun-22 23:22pm    
I would like to use the C++ class in the C# application, so I decided on a way to use C++/CLI.
The C++ class has a 'throw std::exception', it will be thrown in C++/CLI.

Sorry for the lack of my explanation and short English.

Is using unmanaged code's exception in managed code not appropriate?
Richard MacCutchan 1-Jul-22 3:24am    
You misunderstand what is happening. Your code is throwing an exception, so you need to investigate why it is doing that.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900