C#异常处理程序接下来继续 [英] C# exception handler resume next

查看:191
本文介绍了C#异常处理程序接下来继续的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在调查如何在异常发生时更改c#方法执行的行为:

I’ve been investigating how I can alter the behaviour of c# method execution specifically when an exception occurs to support:

重试/继续:能够尝试再次执行相同的声明,并继续执行
跳过/恢复:移动到下一个语句并继续执行

Retry/Continue: to be able to try the same statement again and carry on once successful Skip/Resume: moves to the next statement and continues with execution

我已经阅读了许多回应是糟糕的编码实践,但这是一个代码转换器,它从支持此功能的语言转换了数百万行代码。我需要这个功能一致。

I’ve read the many responses that this is poor coding practice, but this is for a code converter, which is converting millions of lines of code from a language where this functionality is supported. I need this to be functionally consistent.

推荐答案

您唯一的选择可能是采用(坦率的恐怖)风格: / p>

Your only option could be to adopt a (frankly horrible) style like this:

var done = false;
while (!done) { try { line1(); done = true; } catch {} }
done = false;
while (!done) { try { line2(); done = true; } catch {} }
// etc

混合:

try { line1(); } catch {}
try { line2(); } catch {}
// etc

放心,有数以百万计的这样的行将会在其余的一段时间里,维持生活非常困难和烦人。

Rest assured that having millions of such lines will make it very hard and annoying to maintain for the rest of its life.

这篇关于C#异常处理程序接下来继续的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆