C# exception handler resume next

限于喜欢 提交于 2019-12-25 08:42:05

问题


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.


回答1:


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

Mixed with:

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.



来源:https://stackoverflow.com/questions/42201896/c-sharp-exception-handler-resume-next

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!