Back to Devexpress

EnvironmentPolicy.Failed Event

corelibraries-devexpress-dot-data-dot-utils-dot-environmentpolicy-ded0d0f1.md

latest4.6 KB
Original Source

EnvironmentPolicy.Failed Event

Allows you to respond to associated failures (exceptions and errors).

Namespace : DevExpress.Data.Utils

Assembly : DevExpress.Data.v25.2.dll

NuGet Package : DevExpress.Data

Declaration

csharp
public static event EventHandler<EnvironmentPolicy.FailedEventArgs> Failed
vb
Public Shared Event Failed As EventHandler(Of EnvironmentPolicy.FailedEventArgs)

Event Data

The Failed event's data class is EnvironmentPolicy.FailedEventArgs. The following properties provide information specific to this event:

PropertyDescription
ExceptionGets the exception.
OperationGets the environment-related operation that failed.
ThrowGets or sets whether to throw an exception.

The event data class exposes the following methods:

MethodDescription
ToString()Returns a human-readable representation of the FailedEventArgs object, which can be useful for debugging, logging, or understanding the failure.

Remarks

The Failed event occurs when the EnvironmentPolicy throws an exception and allows you to respond to the associated failure. Set the e.Throw event parameter to false to suppress the exception (e.Exception). The e.Operation parameter identifies the environment-related operation that failed.

csharp
using System;
using System.Windows.Forms;

namespace EnvironmentPolicyDemo {
    internal static class Program {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            DevExpress.Data.Utils.EnvironmentPolicy.ThrowAlways();
            DevExpress.Data.Utils.EnvironmentPolicy.Failed += EnvironmentPolicy_Failed;
            Application.Run(new Form1());
        }

        static void EnvironmentPolicy_Failed(object sender, DevExpress.Data.Utils.EnvironmentPolicy.FailedEventArgs e) {
            Console.WriteLine(e.Exception.Message);
            e.Throw = false;
        }
    }
}
vb
Imports System
Imports System.Windows.Forms

Namespace EnvironmentPolicyDemo
  Friend Module Program
    ''' <summary>
    ''' The main entry point for the application.
    ''' </summary>
    <STAThread>
    Sub Main()
      Application.EnableVisualStyles()
      Application.SetCompatibleTextRenderingDefault(False)
      DevExpress.Data.Utils.EnvironmentPolicy.ThrowAlways()
      AddHandler DevExpress.Data.Utils.EnvironmentPolicy.Failed, AddressOf EnvironmentPolicy_Failed
      Application.Run(New Form1())
    End Sub

    Private Sub EnvironmentPolicy_Failed(ByVal sender As Object, ByVal e As DevExpress.Data.Utils.EnvironmentPolicy.FailedEventArgs)
      Console.WriteLine(e.Exception.Message)
      e.Throw = False
    End Sub
  End Module
End Namespace

Use the following methods to trace and handle exceptions:

  • ThrowAlways() – Throws an exception when the DevExpress control accesses System.Environment.
  • ThrowOnErrors() – Throws an exception if a request to System.Environment fails.

Tip

Read the following topic for additional information: Environment Policy.

See Also

ThrowAlways()

ThrowOnErrors()

EnvironmentPolicy Class

EnvironmentPolicy Members

DevExpress.Data.Utils Namespace