尝试捕获每一行代码,而无需单独的try-catch块 [英] Try-catch every line of code without individual try-catch blocks
问题描述
我目前没有这个问题,但您永远不知道,并且认为实验总是很有趣。
I do not currently have this issue, but you never know, and thought experiments are always fun.
忽略要尝试这种操作,您的体系结构就必须要解决一些明显的问题,我们假设您有一些别人设计的可怕代码,并且需要在其中进行一系列广泛多样的操作相同的代码块,例如:
Ignoring the obvious problems that you would have to have with your architecture to even be attempting this, let's assume that you had some horribly-written code of someone else's design, and you needed to do a bunch of wide and varied operations in the same code block, e.g.:
WidgetMaker.SetAlignment(57);
contactForm["Title"] = txtTitle.Text;
Casserole.Season(true, false);
((RecordKeeper)Session["CasseroleTracker"]).Seasoned = true;
乘以100。其中一些可能会起作用,另一些可能会严重出错。您需要的是与C#等价的下一步错误恢复,否则您将最终在许多代码行中复制并粘贴try-catching。
Multiplied by a hundred. Some of these might work, others might go badly wrong. What you need is the C# equivalent of "on error resume next", otherwise you're going to end up copying and pasting try-catches around the many lines of code.
您将如何解决这个问题?
How would you attempt to tackle this problem?
推荐答案
很明显,您是用VB.NET编写代码的,实际上确实具有在错误恢复下一个 ,并将其导出到DLL中到C#。其他任何东西都只是being嘴
。
It's pretty obvious that you'd write the code in VB.NET, which actually does have On Error Resume Next, and export it in a DLL to C#. Anything else is just being a glutton for punishment.
这篇关于尝试捕获每一行代码,而无需单独的try-catch块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!