Exception Handling in Django - Is this necessary?
<p>Is this:</p>

<pre><code>@login_required
def remove_photo(request):
    if request.is_ajax():
        try:
            BirdPhoto.objects.get( pk = request.POST.get('image_id') ).delete()
        except Exception:
            raise Exception
        return HttpResponse(json.dumps({'msg':'success'}), content_type='application/json')
</code></pre>

<p>better than this:</p>

<pre><code>@login_required
def remove_photo(request):
    if request.is_ajax():
        BirdPhoto.objects.get( pk = request.POST.get('image_id') ).delete()
        return HttpResponse(json.dumps({'msg':'success'}), content_type='application/json')
</code></pre>

<p>? I have to admit, I don't pay as much attention to error handling and testing as I should.  So I just wrote this new function, and I was thinking I should make sure I am handling the errors.  Once I kind of got to the basic level of handling errors, I looked at it and said to myself: this isn't really doing anything.  It seems to me the two functions will act the same way.  This is django, so in production environment the server should catch this and just return a general http response.  Am I OK leaving it as the 4 line version and instead of the 6 line version?</p>

<p>First of all, is there a reason not to use <a href="https://docs.djangoproject.com/en/1.10/ref/class-based-views/generic-editing/#deleteview" rel="nofollow"><code>DeleteView</code></a>?</p>

<p>If so, it seems like using <a href="https://docs.djangoproject.com/en/1.10/topics/http/shortcuts/#get-object-or-404" rel="nofollow"><code>get_object_or_404</code></a> is the most suitable solution:</p>

<pre><code>@login_required
def remove_photo(request):
    if request.is_ajax():
        get_object_or_404(BirdPhoto, pk=request.POST.get('image_id')).delete()
        return HttpResponse(json.dumps({'msg':'success'}), content_type='application/json')
</code></pre>

python django error-handling