例外消息:Constructor on type StateLog not found.
我有以下代码,不适用于只有一个类:
List<T> list = new List<T>();
string line;
string[] lines;
HttpWebResponse resp = (HttpWebResponse)HttpWebRequest.Create(requestURL).GetResponse();
using (var reader = new StreamReader(resp.GetResponseStream()))
{
while ((line = reader.ReadLine()) != null)
{
lines = line.Split(splitParams);
list.Add((T)Activator.CreateInstance(typeof(T), lines));
}
}
Run Code Online (Sandbox Code Playgroud)
它不起作用的类的构造函数与它工作的其他类完全相同.唯一的区别是这个类将传递16个参数而不是2-5.构造函数看起来像这样:
public StateLog(string[] line)
{
try
{
SessionID = long.Parse(line[0]);
AgentNumber = int.Parse(line[1]);
StateIndex = int.Parse(line[5]);
....
}
catch (ArgumentNullException anex)
{
....
}
}
Run Code Online (Sandbox Code Playgroud)
就像我说的,它适用于使用它的其他5个类,唯一的区别是输入的数量.
我有以下代码:
#include <iostream>
using namespace std;
class A {
public:
A() { cout << "A::A()" << endl;}
~A() { cout << "A::~A()" << endl; throw "A::exception";}
};
class B {
public:
B() { cout << "B::B()" << endl; throw "B::exception";}
~B() { cout << "B::~B()";}
};
int main() {
try {
cout << "Entering try...catch block" << endl;
A objectA;
B objectB;
cout << "Exiting try...catch block" << endl;
} catch (char const * ex) {
cout << ex << …Run Code Online (Sandbox Code Playgroud) c++ destructor exception-handling exception constructor-exception