(patch for Bash) try-block and exception

William Park opengeometry at yahoo.ca
Sat Jul 31 15:47:38 EDT 2004


In <comp.unix.shell> William Park <opengeometry at yahoo.ca> wrote:
>     (crossposted to comp.lang.python, because this may be of interest to
>     them.)
> 
> Python has try-block, within which you can raise exception.  Once it's
> raised, execution breaks out of the try-block and is caught at the end
> of try-block.
> 
> Now, Bash has similiar feature.  I've added try-block and 'raise'
> builtin into Bash-3.0.  Typical usage would go something like
>     try
>         echo a
>         raise
>         echo b
>     done
> or
>     try 
>         echo a
>         raise 2
>         echo b
>     done in
>         0) echo okey ;;
>         1) echo raised 1 ;;
>         2) echo raised 2 ;;
>         *) echo really bad ;;
>     esac

Typo... I pasted an old example.  No globbing or any shell expansion is
done.
    try 
	echo a
	raise 2
	echo b
    done in
	0) echo okey ;;
	1) echo raised 1 ;;
	2) echo raised 2 ;;
    esac

> 
> The exception is positive integer and is raised by 'raise' builtin, just
> like 'break' for the for/while/until loops.  And, it can be caught by
> using optional case-like statement.
> 
> Ref:
>     http://freshmeat.net/projects/bashdiff/
>     help try
>     help raise

-- 
William Park, Open Geometry Consulting, <opengeometry at yahoo.ca>
Toronto, Ontario, Canada



More information about the Python-list mailing list