bellthoven/bangsh

Update boot.sh - show exception message

Opened this issue · 0 comments

boot.sh

## Raises an exception that can be caught by catch statement
## @param exception - a string containing the name of the exception
function b.raise () {
  local exception="$1"
  shift
  if echo "${FUNCNAME[@]}" | grep -q 'b.try.do'; then

    local function=$(echo ${FUNCNAME[1]} |
      sed -e 's/^_\([^.]\+\)\..*/\1/')

    function=${function}.exception.$(echo $exception |
      sed -e 's/\([A-Z]\)/_\L\1/g' -e 's/^_//' -e 's/_exception//')

    echo 'function :' `tput bold`${FUNCNAME[1]}`tput sgr0`
    echo 'exception:' "$exception"
    echo -n 'message  : '
    tput bold
    tput setb 3
    tput setaf 3
    $function
    tput sgr0

    b.set "Bang.Exception.Name" "$exception"
    b.set "Bang.Exception.Msg" "$*"
  else
    b.abort "Uncaught exception $exception: $*"
  fi
}

example:

Outout