Try:Except: Not working

I have a function that has some nested functions inside. The script is called on a barcode scan event. I had to add a custom property called scanBool that sets to 1, then reverts to 0 upon completion. This is so that the code will run completely before allowing another scan input. The outside function is wrapped with a try: except: so that if the function errors out, the scanBool will reset to 0 as to not lock the scanner from further input. I’ve noticed that if one of the nested functions returns an error, the except block is not being used. Do I need to put a try except around every function? Is there a better way to handle this?

Putting the try except around each function call is working. Not sure if that is the best practice, but it works

Shouldn’t be necessary. But consider using a finally clause instead of except for cleanup operations. Also, python won’t catch pure java exceptions unless you use double except clauses, like so:

1 Like