title: What's the sequence of middleware execution in django when error occurs in process_request?
body: <p>I am looking into django middleware codebase. I looked into following diagram<a href="https://i.stack.imgur.com/iKDL1.png" rel="noreferrer"><img src="https://i.stack.imgur.com/iKDL1.png" alt="enter image description here"></a></p>
  
  <p>So, the diagram is quite clear. </p>
  
  <p>But I have some questions</p>
  
  <ol>
  <li><p>What happens when exception comes in process_request() middleware ? How is it handled ? Will the response_middleware be invoked ? Eg. if exception comes in <code>process_view()</code> of <code>AuthenticationMiddleware</code>, then will <code>process_response()</code> of <code>MessageMiddleware</code> be invoked ? </p></li>
  <li><p>What happens when in process_response() middleware returns response?  Eg. if <code>process_view()</code> of <code>AuthenticationMiddleware</code> returns respones, then will <code>process_response()</code> of <code>MessageMiddleware</code> be invoked ?  OR it'll turn back from <code>AuthenticationMiddleware</code>(ie, it'll invoke <code>process_response()</code> of <code>AuthenticationMiddleware</code>, but will not invoke <code>process_response()</code> of <code>MessageMiddleware</code>)</p></li>
  </ol>
  
  <p>I have debugged the behaviour of django in 1.10 where new style middleware classes are used, but I am not familiar about old <code>MIDDLEWARE_CLASSES</code> settings ?</p>
  
  <p>For django 1.10:-
  1) If <code>process_request()</code> for <code>AuthenticationMiddleware</code> returns response, then <code>process_template_response()</code> and <code>process_response()</code> will be invoked as show in the figure given below for all the middlewares.</p>
  
  <p>2) If <code>process_request()</code> for <code>AuthenticationMiddleware</code> raises exception, then also the behavior will be the same.</p>
  
  <p>Correct me, If I am wrong.</p>
  
  <p>Thanks in Advance.</p>