I was using \"exit 1\" statement in my bash functions to terminate the whole script and it worked fine:
function func() { echo \"Goodbye\" exit 1 } ech
You can use set -e which exits if a command exits with a non-zero status:
set -e
set -e func set +e
Or grab the return value:
(func) || exit $?