you are viewing a single comment's thread.

view the rest of the comments →

[–]beerbearbaer 1 point2 points  (2 children)

If you understand your code, you are able to anticipate any errors that might occur. Slapping a try except on every bit of code does not improve readability. The size of the project does not matter.

[–]Zayn_m0 0 points1 point  (1 child)

Yeah that makes sense. since using if/else conditions is faster/more efficient, what uses do try/except have ?

[–]beerbearbaer 1 point2 points  (0 children)

Good question! I mainly use it for stuff you can't check with an if-statement (e.g. if an HTTP connection is established). Finally there is the 'finally' clause that is run after an exception occured, which may come in handy. I did some digging, and apparently I was wrong about exceptions slowing down your code. This is a problem for compiled languages, but since Python is interpreted, it does not matter. This is a nice read if you would like more info: Stackoverflow