Определение типа исключения

Обработка исключений

#an error type is a code of its own: from 3 to 125,
#with a name that says what it means
readonly errEmptyName=3

checkName() {
    if [[ -z $1 ]]; then
        echo "Oops! The name is empty" >&2
        return "$errEmptyName"
    fi
}

#set -e ends the shell at the first command that fails,
#like an exception that nobody catches; ( ) keeps the script going
(
    set -e
    checkName ""
    echo "not printed"
) 2> /dev/null
code=$?
#code is 3

#bash has codes of its own: 127 - command not found,
#126 - the file is not executable, 128 + n - killed by the signal n
noSuchCommand 2> /dev/null
notFound=$?
#notFound is 127

echo "code is $code"
echo "notFound is $notFound"