gpt4 book ai didi

c# - 即使在 try catch 之后继续执行程序

转载 作者:行者123 更新时间:2023-11-30 18:50:39 30 4
gpt4 key购买 nike

当我使用 try、catch block 时,如果抛出任何异常,程序将在处理 catch 后停止执行。但是,即使有异常,我也需要继续执行程序。任何人都可以帮助我怎么做吗?

最佳答案

如果我没理解错的话,这就是你想要的:

try
{
Statement1(); // <-- Exception is thrown in here
Statement2(); // <-- You want to go here after the catch block executes
}
catch
{
HandleException();
}

Try/catch block 不是那样工作的。您将不得不按如下方式重写代码:

try
{
Statement1();
}
catch
{
}


try
{
Statement2();
}
catch
{
}

关于c# - 即使在 try catch 之后继续执行程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4557319/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com