title: why is it necessary to implement a provider that throws exception when you manually seed a value?
body: <p>While using google guice I came across this documentation of how to manually seed values in request scope. </p>
  
  <p>[<a href="https://github.com/google/guice/wiki/ServletModule#dispatch-order]" rel="nofollow noreferrer">https://github.com/google/guice/wiki/ServletModule#dispatch-order]</a></p>
  
  <p>You can implement a custom filter to seed values to be injected later e.g. </p>
  
  <pre><code>   protected Filter createUserIdScopingFilter() {
       return new Filter() {
         @Override public void doFilter(
            ServletRequest request,  ServletResponse response, FilterChain chain)
             throws IOException, ServletException {
           HttpServletRequest httpRequest = (HttpServletRequest) request;
           // ...you'd probably want more sanity checking here
           Integer userId = Integer.valueOf(httpRequest.getParameter("user-id"));
           httpRequest.setAttribute(
               Key.get(Integer.class, Names.named("user-id")).toString(),
               userId);  
           chain.doFilter(request, response);
         }
  
        @Override public void init(FilterConfig filterConfig) throws ServletException { }
  
        @Override public void destroy() { }
       };
    } 
  </code></pre>
  
  <p>In this documentation they are explaining the binding as </p>
  
  <p>And the binding might look like this:</p>
  
  <pre><code>  public class YourServletModule extends ServletModule {
       @Override protected void configureServlets() {
           .....
          filter("/process-user*").through(createUserIdScopingFilter());
      }
  
      @Provides @Named("user-id") @RequestScoped Integer provideUserId() {
        throw new IllegalStateException("user id must be manually seeded");
      }
    }
  </code></pre>
  
  <p>I would like to understand why is it necessary to implement a provides method that throws an exception ? What is its purpose ?</p>