Contract.ContractFailed Event

Definition

Occurs when a contract fails.

public:
 static event EventHandler<System::Diagnostics::Contracts::ContractFailedEventArgs ^> ^ ContractFailed;
public static event EventHandler<System.Diagnostics.Contracts.ContractFailedEventArgs> ContractFailed;
public static event EventHandler<System.Diagnostics.Contracts.ContractFailedEventArgs>? ContractFailed;
[add: System.Security.SecurityCritical]
[remove: System.Security.SecurityCritical]
public static event EventHandler<System.Diagnostics.Contracts.ContractFailedEventArgs> ContractFailed;
member this.ContractFailed : EventHandler<System.Diagnostics.Contracts.ContractFailedEventArgs> 
[<add: System.Security.SecurityCritical>]
[<remove: System.Security.SecurityCritical>]
member this.ContractFailed : EventHandler<System.Diagnostics.Contracts.ContractFailedEventArgs> 
Public Shared Custom Event ContractFailed As EventHandler(Of ContractFailedEventArgs) 

Event Type

Attributes

Remarks

The event information for this event is supplied by the System.Diagnostics.Contracts.ContractFailedEventArgs object that is passed to the event handler. This event notifies a managed application environment such as an interactive interpreter or a Web browser host that a contract has failed. Before doing so, it will raise an event that an application can handle as it sees fit. For example, if code is being run in a testing framework, you can log a test failure and then end the test.

The default implementation of the RaiseContractFailedEvent method in the .NET Framework class library is to call each handler that is registered with the ContractFailed event. Exceptions thrown by handlers are ignored, but each handler can indicate whether the failure is handled by calling the SetHandled method for the event arguments. If any handler sets the failure as handled, the method returns null and no further action is taken. Alternatively, handlers can call the SetUnwind method to instruct the code to unwind. In that case, an exception is thrown after all handlers have executed.

Applies to