I have a question on using Enterprise Library Exception Handling Application Block.
First is the "ExceptionManager.Process" method. what I understood from the documentation is that you can execute your desired method and if it has an exception the ExceptionManager handles it, and it does not need any try-catch block. but when I use it it throws the exception.
builder.ConfigureExceptionHandling()
.GivenPolicyWithName("Data Access Policy")
.ForExceptionType<Exception>()
.LogToCategory("General")
.WithSeverity(System.Diagnostics.TraceEventType.Error)
.UsingEventId(9000)
.WrapWith<InvalidOperationException>()
.UsingMessage("MyMessage").ThenDoNothing();
#endregion
var configSource = new DictionaryConfigurationSource();
builder.UpdateConfigurationWithReplace(configSource);
EnterpriseLibraryContainer.Current = EnterpriseLibraryContainer.CreateDefaultContainer(configSource);
#endregion
var exManager = EnterpriseLibraryContainer.Current.GetInstance<ExceptionManager>();
exManager.Process(GenerateException, "Data Access Policy");
}
private static void GenerateException()
{
throw new NullReferenceException();
}
I have used fluent-API for configuring application block. I want to log the exception to database and I have configured it well. The ExeptionManager.HandleException works well but it needs to be in an try-catch block.
how can I use "Process" method that handles exception without interruption and without a try-catch block ?