If you need to do some cleanup whether or not a part of a bash script ran successfully, but also want to exit immediately if other stuff in that script fails, use a subshell:

set -e # exit immediately on error

touch fileThatAlwaysGetsRemoved # if this fails it exits without the cleanup

( # <--- subshell
  set -e 


rm fileThatAlwaysGetsRemoved