#!/bin/sh

error_handler() {
  progname="$0"
  LINE="$1"
  EXIT_CODE="$2"
  >&2 echo "${progname}: Error in line ${LINE} (exit code ${EXIT_CODE})"
  exit "${EXIT_CODE}"
}

exit_clean() {
  trap - ERR INT TERM
  exit "$1"
}

# the error handler trap must be set within the subshell to be effective
trap 'error_handler ${LINENO} $?' ERR INT TERM
set -e
set -o xtrace

echo "Beginning experiment"
false || true
# if [ "$1" = '-f' ]; then
#   exit 1
# fi
echo "Proceeding to Normal Exit"
# exit_clean 0
# exit_clean 0
