Hacker News new | ask | show | jobs
by emidln 3929 days ago
I've seen exceptions masquerading as goto in the wild in multiple python codebases (and not because I added them). `raise HttpResponse(status=401, body="unauthorized")` inside some utility method is little more than goto exit in a lot of C code.
1 comments

Using Exceptions this way in Python code is common practice and considered "Pythonic" and it's different than goto:

- an Exception only can bubble up the call stack, not to an arbitrary location in the code

- it can be caught whatever level during that path