【发布时间】:2023-03-16 04:00:01
【问题描述】:
在查看 C# try catch 教程时,我遇到了以下问题。我的示例代码如下,
在 mainMethod() 内部,我需要调用三个单独的方法。在testMethodOne() 内部,我需要处理异常。如果testMethodOne()抛出异常,不执行testMethodTwo(dt),mainMethod()抛出异常。如果testMethodOne() 抛出异常,我需要调用testMethodTwo(dt); 和testMethodThreee(dt);,我该怎么做。
public void MainMethod(data dt){
try{
testMethodOne(dt);
testMethodTwo(dt);
testMethodThreee(dt);
}catch(Exception ex){
throw ex;
}
}
public void testMethodOne(dt){
try
{
// Block of code to try
}
catch (Exception e)
{
// Block of code to handle errors
}
}
【问题讨论】: