There are many issues with the 'set -e' - it does not work well in many error conditions. This has been covered in many posting, just search 'errexit bash'. For example: Bash subshell errexit semantics
At this time, there is no clean solution. However, there are good news. I'm working on a proposed change that will allow the above to work. See discussion in bash-bug archive: https://lists.gnu.org/archive/html/bug-bash/2022-07/index.html
And proposal: https://lists.gnu.org/archive/html/bug-bash/2022-07/msg00006.html
Final proposal for the 'errfail' can be found: https://lists.gnu.org/archive/html/bug-bash/2022-07/msg00055.html
I expect to have the solution submitted for review by the bash dev team this week. Hopefully it will get accepted into next bash release.
It will support new 'errfail' option
set -o errfail
{ echo BEFORE ; false ; echo AFTER ; } || echo "CATCH"
and will output: BEFORE CATCH
If you are looking for more fancy solution consider:
alias try=''
alias catch='||'
try {
echo BEFORE
false
echo AFTER
} catch { echo CATCH ; }