Skip to main content

All Questions

Tagged with
1 vote
2 answers
222 views

Is nesting try-except sequence in try-else block bad form?

Ive got a boot sequence that needs to check some registry values, they may or may not be present, so each check needs to be wrapped in its own try-except. I try to avoid nesting as I think it can lead ...
pstatix's user avatar
  • 1,047
3 votes
1 answer
2k views

Handling same exception thrown by different methods

Is there an idiomatic way to catch an exception when multiple methods may throw?: try: someMethod() # raises OSError someOtherMethod() # raises OSError except OSError: handle() The ...
pstatix's user avatar
  • 1,047
32 votes
10 answers
10k views

What is a good approach to handling exceptions?

I have trouble reconciling "best practices" and real-world approaches to handling exceptions. In my day to day routine, I find myself running into the following examples: try: ...
Jakov's user avatar
  • 475
4 votes
2 answers
263 views

Design of multi-test function to validate a string

Assume that I wish to perform an action on a string (e.g., print the string) if, and only if, the string first passes several tests. The tests are diverse (and may even be complex functions themselves)...
Michael Gruenstaeudl's user avatar
5 votes
4 answers
6k views

Should exceptions be raised higher up or lower down or both? [closed]

When calling some function in a Python application, the function often calls functions deeper down which again call functions deeper down, etc. It is easy to unknowlingly pass a bad value to the top-...
cmeeren's user avatar
  • 339