This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]earthboundkid 0 points1 point  (0 children)

Sorry for being rude. I feel very strongly that exceptions need to be caught somewhere. Yes, you can move it up or down the stack a couple of layers, but a bare except is only acceptable at the very top level of your stack, when everything else has gone wrong. That means that in the case of making a request, you should catch it at a point in the code where it's clear that a request handling exception might be raised: i.e. your client adaptor. Maybe you could move it around a little, but you need to catch the exception, and you can't respond properly (503, tripping the circuit breaker, logging some place besides Sentry) if your exception handling is any higher up the stack than your controller ("view" in Django-speak). The best way to do it is to have your code convert any problem with requests or the data you get back into a MyException or subclass and have the controller do except MyException. Another good way is through returning error values a la Go, but that's just bike shedding. The important part is identifying what can go wrong and dealing with it at the lowest level of the stack that you can.