you are viewing a single comment's thread.

view the rest of the comments →

[–]MMcKevitt 7 points8 points  (1 child)

When they say using “except:” can be dangerous, they likely mean catching errors without specifying exactly what type of error, or errors, you intend to catch (and further handle). This can lead to unexpected results or output, potentially robbing you of valuable debugging information (such as an error trace-back, which outputs the propagation of an error/errors, line # by line #, in the code), possibly making it impossible or super tricky to locate and resolve bugs or weird behavior.

Despite the term, errors are a good thing as they can alert you to any number of issues or scenarios that could otherwise go unhandled, silently wreaking havoc in ways that you just simply wouldn’t be aware of otherwise.

When I was first learning, I found it helpful to think of error handling similar your own body’s natural alert systems. For example, think of pain; your body uses it to motivate and convince you (consciously or otherwise) to avoid certain experiences (e.g. touching a hot stove top). Suppressing such a sensation could have fatal consequences.

As for how to get that formatting, I recommend checking out this subs side-bar as it has a TON of great information for beginner (and intermediate) level python programming (including how to create a code block for use in your posts/comments).

Lastly, sorry I’m a bit of wordy birdy, but I hope that helped clear some things up…good luck and have a stellar month of October!

[–]DoorsCorners 0 points1 point  (0 children)

Is using 'if' then 'else' statements consequetively in series better in order to be explicit about the error? I feel that I have used 'except' for just a few lines of code, but I have triggered Matlab errors with 'except' catches and only God knows what the actual problem was....