title: django: raise BadRequest as exception?
body: <p>Is it possible to raise <code>BadRequest</code> as exception in django?</p>
  
  <p>I have seen that you can raise a 404 [1].</p>
  
  <p>Use case: in a helper method I load a json from request.GET. If the json was cut since the browser (IE) cut the url, I would like to raise a matching exception.</p>
  
  <p>A BadRequest exception looks appropriate, but up to now there seems to no such exception in django.</p>
  
  <p>In 1.6 there is a  SuspiciousOperation exception. But this does not match in my case, since it is not security related.</p>
  
  <p>Of course I could put a try..except around my helper method in the view method, but this is not DRY.</p>
  
  <p>Has someone a solution where I don't need a try..exception around every call of my helper method?</p>
  
  <p>[1] <a href="https://docs.djangoproject.com/en/1.6/ref/exceptions/#django.core.urlresolvers.Resolver404">https://docs.djangoproject.com/en/1.6/ref/exceptions/#django.core.urlresolvers.Resolver404</a></p>
  
  <p><strong>Update</strong></p>
  
  <p>Code example:</p>
  
  <pre><code>def my_view(request):
      data=load_data_from_request(request) # I don't want a try..except here: DRY
      process_data(data)
      return django.http.HttpResponse('Thank you')
  
  def load_data_from_request(request):
      try:
          data_raw=json.loads(...)
      except ValueError, exc:
          raise BadRequest(exc)
      ...
      return data
  </code></pre>