代码合约错误
有没有办法改变代码契约在运行时的行为方式?例如,当运行时前置条件或后置条件失败时,应用程序就会崩溃。有没有一种方法可以显示 MessageBox 而不是崩溃?
is there a way to alter the way the code contracts behave during run time? as in, when a pre or post conidtion fails during run time, the application crashes. Is there a way instead of crashing, have a MessageBox displayed??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当合约失败时,程序不会“崩溃”,但会抛出异常。 Contracts 类让您可以控制异常类型。
因此,您需要某种形式的异常处理,而不仅仅是合同。
话虽如此,失败的合同通常严重到足以终止申请。
When a contract fails the program does not 'crash' but an Exception is thrown. The Contracts class lets you control what kind of exception.
So you need some form of Exception Handling, and not just for the Contracts.
Having said that, a failing Contract is usually severe enough to terminate the application.