C++ cli c+中的例外处理+/cli

C++ cli c+中的例外处理+/cli,c++-cli,C++ Cli,实际上,我正在使用c++dll开发c++/CLI dll,而c++/CLI dll将从本机c使用。 c++/cli代码类似于:- public ref class Class1 { // TODO: Add your methods for this class here. public: static Managed_EMV_DLL::Managed_EMV ^obj = gcnew Managed_EMV(); // object of c# class bo

实际上,我正在使用c++dll开发c++/CLI dll,而c++/CLI dll将从本机c使用。
c++/cli代码类似于:-

public ref class Class1
{
    // TODO: Add your methods for this class here.
public:
     static Managed_EMV_DLL::Managed_EMV ^obj = gcnew Managed_EMV(); // object of c#   class
     bool INIT_READER(unsigned int *);
     bool READ_KEY(unsigned int *ERROR_CODE,unsigned char *RETURN_ARRAY, unsigned int *Array_LENGTH);

};
-我想用c++/CLI代码处理异常,
-未找到c#dll时处理异常。
我怎样才能做到。

你面临的确切问题是什么。。。。请参见下面的示例格式

try 
 {
 }
catch(FormatException ^) // display an appropriate message
 {
   Console::WriteLine(L"You must enter a valid number "
                               L"and no other character!");
 }

只需找出可能从C#dll引发的异常,然后在C++/CLI代码中放入适当的句柄。

我想处理任何类型的异常,而不仅仅是FormatException或TypeInitializationException。 在这里,我编写的代码如下:-

try
{

}
catch (Exception^ ex) 
{ 
Console::WriteLine("Error in C++/CLI INIT function: {0}", ex->ToString());
} 
catch (...) 
{ 
      Console::WriteLine("Error in INIT");
}

而且效果很好。。。。我希望它能抓住任何例外

不能,代码中没有引发异常。当JIT编译器无法编译类的类型初始值设定项(也称为静态构造函数)时,它将出现在客户机代码中,由JIT编译器引发。由于客户机代码是C,因此捕获和诊断异常非常困难。从技术上讲_try/__except是可能的,但您对SEH异常的原因一无所知。如何将Class1的第一次引用包装到另一个公开公共方法的类型中,在该方法中放入try/catch,然后从客户端代码调用它?