Back to Devexpress

EnvironmentPolicy.ThrowAlways() Method

corelibraries-devexpress-dot-data-dot-utils-dot-environmentpolicy-29c65fb0.md

latest2.9 KB
Original Source

EnvironmentPolicy.ThrowAlways() Method

Throws an exception when the DevExpress control accesses System.Environment.

Namespace : DevExpress.Data.Utils

Assembly : DevExpress.Data.v25.2.dll

NuGet Package : DevExpress.Data

Declaration

csharp
public static void ThrowAlways()
vb
Public Shared Sub ThrowAlways

Remarks

Call the ThrowAlways method at application startup to apply a restrictive policy. Handle the Failed event to respond to associated failures.

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

Tip

Read the following topic for additional information: Environment Policy.

See Also

ThrowOnErrors()

EnvironmentPolicy Class

EnvironmentPolicy Members

DevExpress.Data.Utils Namespace