就是如何让继续上一次出现异常的地方后面的程序 public class class1
{
public void mothed()
{
class2 c = new class2();
c.method();
//do something1...
}
}
public class class2
{
public void method()
{
throw new Exception("error");
//do something2...
}
}
比如上面,有二个要求。
1是如何让程序下次继续运行do something1下面的程序?
2是如何让程序下次继续运行do something2下面的程序?没有限制使用方法来实现这两个要求,设计新的类什么的都行
{
public void mothed()
{
class2 c = new class2();
c.method();
//do something1...
}
}
public class class2
{
public void method()
{
throw new Exception("error");
//do something2...
}
}
比如上面,有二个要求。
1是如何让程序下次继续运行do something1下面的程序?
2是如何让程序下次继续运行do something2下面的程序?没有限制使用方法来实现这两个要求,设计新的类什么的都行
{
method();
}
catch
{
try
{
method1();
}
catch
{
}
}
{
class2 c = new class2();
public void mothed()
{
if (!c.isError)
{
try
{
c.method();
}
catch (Exception ex)
{
if (ex.Message == "error")
{
c.isError = true;
//.....................
}
}
}
else
{
//do something1...
}
}
}
public class class2
{
public bool isError = false;
public void method()
{
if (!isError)
{
throw new Exception("error");
}
else
{
//do something2...
}
}
}
另外,我对“下次”不大理解,是否是程序退出之后再次进入?那就需要序列化(保存)一些信息,下次启动时读取这些信息。
public class class1
{
public void mothed()
{
class2 c = new class2();
c.method();
//do something1...
Console.WriteLine("here!");
}
}
public class class2
{
public void method()
{
try
{
throw new Exception("error");
}
catch
{ }
finally
{
//do something2...
}
}
}
另外是throw new Exception("error")有加逻辑判断的,并不是每次都是出错。