Custom Exception Filter not being called in asp.net core mvc application

I am having a Custom Exception filter called ExceptionFilter. It is registered globally in the startup class but when I throw the exception in my code the filter never gets called.

public class ExceptionFilter:IExceptionFilter
{
    public void OnException(ExceptionContext context)
    {
        if (context.Exception is ForceException)
        {
            context.HttpContext.Response.StatusCode = StatusCodes.Status400BadRequest;
        }
    }
}

Startup.cs

 services.AddMvc(
            config => {
                config.Filters.Add(typeof(ExceptionFilter));
            });