Polly icon indicating copy to clipboard operation
Polly copied to clipboard

Allow Handle to use function call without Exception generic type

Open bunceg opened this issue 11 years ago • 2 comments

Hi,

Handle expects an exception each time. This makes it difficult to have standard policy handlers using a decorator pattern across the system. This is because the exception to trap may be different based on the context, i.e. In one part of the system the exception may be System.TimeoutException, in another it may be a SqlException, but the Policy handling is the same.

Either allow injection of the Handle logic via DI with an interface, or allow Handle to take a function method that just returns a bool, thereby allowing in-line anonymous methods to do a similar job to DI

Thanks!

bunceg avatar Jan 13 '15 15:01 bunceg

You can have a policy handle System.Exception, all exceptions inherit from that.

tdietrich513 avatar Jan 13 '15 19:01 tdietrich513

Tom is correct. You can do this:

Policy.Handle<Exception>(ex => /* Generic logic here */)

michael-wolfenden avatar Jan 13 '15 19:01 michael-wolfenden