The exit code has to be a number, but you are using a full exception instance here. What might work is err.errno. But we might have to check what the bash shell gives us when checking the latest exit code.