link: https://medium.com/@dirk.avery/the-bash-trap-trap-ce6083f36700
#!/bin/bash
set -e
trap 'catch $? $LINENO' EXIT
catch() {
echo "catching!"
if [ "$1" != "0" ]; then
# error handling goes here
echo "Error $1 occurred on $2"
fi
}
simple() {
badcommand
echo "Hi from simple()!"
}
simple
echo "After simple call"
link: https://medium.com/@dirk.avery/the-bash-trap-trap-ce6083f36700