catch块的每一行代码

catch块的每一行代码

本文介绍了C#的try-catch没有单独的try-catch块的每一行代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前没有这个问题,但你永远不知道,和思想实验总是很有趣。

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;



由一百相乘。其中的一些可能的工作,其他人可能会去严重错误。你需要的是C#相当于在错误恢复下一步,否则你会最终复制和粘贴周围的代码的多行尝试,渔获物。

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#。还有什么是摆明了处罚馋嘴

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.

这篇关于C#的try-catch没有单独的try-catch块的每一行代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 06:30