Exception Handling With using Exception Policy??

Topics: Enterprise Library Core, Exception Handling Application Block, Logging Application Block, Policy Injection Application Block
Oct 13, 2008 at 5:50 AM
Is it possible to use the Exception handling block and pass all exception to Logging Application Block to log the problem without using "try catch" and following code?

ExceptionPolicy.HandleException(ex, "Logging Policy");

Or we still need to define "try catch" under every functions?

Oct 13, 2008 at 2:18 PM

Yes, you need to catch exceptions at some point. You can create some helper method taking a delegate and a policy name to avoid writing the try/catch every time, though.

Oct 13, 2008 at 2:32 PM
Thanks Fernando

BTW, any reference to create the helper method??

Oct 13, 2008 at 6:17 PM
Something like this should help

        public static void RunAndHandleExceptions<T>(Action action, string policyName)

            where T : Exception


            // null checks for action and policyName here






            catch (T exception)


                if (ExceptionPolicy.HandleException(exception, policyName))






Which you can invoke doing



                () =>


                    // do something here

                    int foo = 1 / zero;