public static void Main()
Console.WriteLine("Hello World");
public interface IExceptionHandler
void HandleException<T>(T exception) where T : Exception;
public interface IExceptionHandler<T> where T : Exception
void Handle(T exception);
public class CustomExceptionHandler : IExceptionHandler, IExceptionHandler<Exception>
private readonly bool _allowInheritanceMode;
public CustomExceptionHandler(bool allowInheritanceMode)
_allowInheritanceMode = allowInheritanceMode;
public void HandleException<T>(T exception) where T : Exception
var handler = this as IExceptionHandler<T>;
handler.Handle(exception);
else if (_allowInheritanceMode)
this.Handle(exception as dynamic);
public void Handle(Exception exception)
protected virtual void OnFallback(Exception exception)
public class LoggerExceptionHandler<T> : CustomExceptionHandler, IExceptionHandler<T> where T : Exception
private static readonly ILog Logger = LogManager.GetLogger<IExceptionHandler<T>>();
public LoggerExceptionHandler(bool allowInheritanceMode) : base(allowInheritanceMode)
public void Handle(T exception)
protected override void OnFallback(Exception exception)