I want to handle different exceptions in such way that there will be common handling for any exception and additional specific handling for subprocess.CalledProcessError. Like this:
try:
check_output(shlex.split(rsync_cmd))
except CalledProcessException as e:
# do some stuff
# do common exception handling
except Exception as e:
# do the same common handling
I don't want to duplicate code so currently I end up with this code:
try:
check_output(shlex.split(rsync_cmd))
except Exception as e:
if isinstance(e, CalledProcessError) and e.returncode == 24:
# do some stuff
# do common handling
What's the best practice to run specific code for one exception and to run common code for all exceptions at the same time?