Code: Select all
#include "pch.h"
#include
namespace ExceptionTestAppCPP
{
class CPPClass
{
public:
void Test()
{
throw new std::exception("Test exception");
}
};
}
Code: Select all
#pragma once
#include
#include
namespace ExceptionTestAppCLR
{
public ref class CLRClass
{
public:
void Test()
{
try
{
ExceptionTestAppCPP::CPPClass cppClass;
cppClass.Test();
}
catch (std::exception* ex)
{
throw;
}
catch (...)
{
throw;
}
}
};
}
namespace ExceptionTestAppCSharp
{
internal class Program
{
static void Main(string[] args)
{
try
{
var clr = new ExceptionTestAppCLR.CLRClass();
clr.Test();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
}
< /code>
Ausführen des Codes führt zu einer statischen Ausnahme in den statischen Libs Cpplass -Test () und fangen von den CLR -Codes CLRCLASS -Test () in seiner Fang (std :: Ausnahme* ex) Block.
Dieses Ergebnis wird erwartet. Seien Sie als System erwischt :: Ausnahme durch den Block (...). entfernt werden und dennoch das Problem verursachen. Handling. Code, den wir verwenden, den wir nicht besitzen oder nicht mehr gepflegt werden.>