Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有办法改变代码合约在运行时的行为方式?例如,当运行时前或后条件失败时,应用程序崩溃。有没有办法,而不是崩溃,有一个消息框显示?
当合同失败时,程序不会“崩溃”,但会引发异常。Contracts 类允许您控制什么样的异常。
所以你需要某种形式的异常处理,而不仅仅是合同。
话虽如此,失败的合同通常严重到足以终止应用程序。