I prefer to write solid shell code, so the errexit & nounset is alway set.
The following code will stop at bad_command line
#!/bin/b
set -o errexit bad_command || { resp_code=$? echo Bad Thing $resp_code happened }