gpt4 book ai didi

c# - 如果 Catch block 本身发生异常,那么如何在 C# 中处理它?

转载 作者:太空狗 更新时间:2023-10-29 17:32:47 24 4
gpt4 key购买 nike

//我在Catch block 中写过代码

 try {

} catch(Excepetion ex) {
// I have written code here If Exception Occurs then how to handle it.
}

最佳答案

您可以在 catch block 中放置一个 try catch,或者您可以简单地再次抛出异常。它最好有finally block 用你的 try catch ,这样即使 catch block 中发生异常,finally block 代码也会被执行。

try
{
}
catch(Excepetion ex)
{
try
{
}
catch
{
}
//or simply throw;
}
finally
{
// some other mandatory task
}

最后 block 可能得不到executed in certain exceptions .你可能会看到 Constrained Execution Regions以获得更可靠的机制。

关于c# - 如果 Catch block 本身发生异常,那么如何在 C# 中处理它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13598026/

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