News for hackers. Stuff that matters.
Re:Python Tips and Traps by mkesper on Tuesday January 20, 2015 @03:01AM (#8915909)
Shouldn't you qualify the exception class as properly as you can? If you can't I'd expect to check for certain error classes you can handle and else reraise the Exception.
Re:Python Tips and Traps by dalke on Tuesday January 20, 2015 @08:19AM (#8916771)
Yes, I would do that in nearly every case.

However, I don't know the larger context. If this were at the top-level of a web services handler where a "return None" indicates a 400 - Internal Server Error, then logging the database failure and stopping is likely acceptable.

Even then, I wouldn't call it good code. However, the goal of this essay seemed to be to give the minimal example, and a more complete example would have required introducing a fake database module with its own exception type. I believe that would have obscured the intent.

I would have preferred real, working code. In this case, with sqlite3. That's fundamentally a pedagogical choice though.