Trying to avoid the FxCop warning ‘Do not raise reserved exceptions’ from a C++/CLI library so I decided to break down and write my own exception type.
[Serializable]
public ref class CaptureException : public Exception
{
public:
CaptureException() : Exception() {}
CaptureException(String^ message) : Exception(message) {}
CaptureException(String^ message, Exception^ inner) : Exception(message, inner) {}
protected:
CaptureException(System::Runtime::Serialization::SerializationInfo^ info, System::Runtime::Serialization::StreamingContext^ context) : Exception(info, context) {}
};
This doesn’t compile stating
error C2664: 'System::Exception::Exception(System::String ^,System::Exception ^)' : cannot convert parameter 1 from 'System::Runtime::Serialization::SerializationInfo ^' to 'System::String ^'
I’m not sure why I’m getting this error. Does the C++/CLI not have the full exception class? I’m just trying to implement the standard constructors for my exception and in C# it looks like this and compiles fine.
[Serializable]
public class CaptureException : Exception
{
public DatabaseConnectionException() { }
public CaptureException (string message) : base(message) { }
public CaptureException (string message, Exception inner) : base(message, inner) { }
protected CaptureException (
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
: base(info, context) { }
}
StreamingContext is a value type (i.e. a struct), so you’ll want to remove the hat ^: