A shell script can capture any signal except 9 (KILL) using the "trap" command. The name of the special signal "ERR" means any non-zero error status.
trap 'error=1' ERR while true; do run-external-program code="$?" if [[ -n "$error" ]]; then echo "Caught an error! Status = $code" error=
You can also tell the shell to ignore errors with an empty command:
trap '' ERR
source share