English 中文(简体)
是否有理由不使用与《法典》合同相符的《长期合同》?
原标题:Is there any reason not to use Run-time Contract Checking with Code Contracts?
最佳回答

在某些非任务关键应用中,你可能实际上想让释放工作中的错误lide倒,而不是在使用者面前 throw错。 终端用户可能永远不会注意到的小ug可能会导致你的合同检查失败,并损害用户的经验。

问题回答

在我看来,使用合同和<>>/em”另一种先决条件检查形式,因为你最终会重复你的前提条件。

使用合同检查你,迫使客户有。 净额4.或以上——就业绩而言,虽然我无法想象这是一个问题,但你最好在作出决定之前对其进行测试。

在许多情况下,如果你想从例外情况中恢复,那么你需要详细了解造成这种情况的原因——这通常涉及创建你自己的例外类别,并作为财产证明你的细节。 使用最基本的例子:<代码> ArgumentOutOfRangeException 载有财产<>code>ActualValue,你可以读出,并根据你的价值决定做些什么。

在使用合同时,如果你的合同失败,就只给你一个基本的<代码>ContractException,该编码是编造的,而且只包含有关合同以示形形式失败的细节,这可能需要一些复杂的平价,才能从中提取你想要的东西——一般而言,你会让双方这样做。

如果你利用自己的例外,就没有理由将合同暂时搁置起来,因为如果合同要失败,就永远不会达到合同损失,那么你只是用不了的指示。

采用静态合同检查以及你自己的例外检查,是消除错误的最有效形式。 大部分时间,你们的例外情况永远不会被thrown弃,因为你再次告诉我们,如何解决问题,然后才能掌握你的意见。





相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...