469,579 Members | 1,145 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,579 developers. It's quick & easy.

(patch for Bash) try-block and exception

(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

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, <op**********@yahoo.ca>
Toronto, Ontario, Canada
Jul 18 '05 #1
6 3054
In <comp.unix.shell> William Park <op**********@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, <op**********@yahoo.ca>
Toronto, Ontario, Canada
Jul 18 '05 #2
William Park <op**********@yahoo.ca> writes:
Ref:
http://freshmeat.net/projects/bashdiff/
help try
help raise


This link doesn't appear to lead to a `download' option..
Jul 18 '05 #3
In <comp.lang.python> Harry Putnam <re****@newsguy.com> wrote:
William Park <op**********@yahoo.ca> writes:
Ref:
http://freshmeat.net/projects/bashdiff/
help try
help raise


This link doesn't appear to lead to a `download' option..


It's two step dance.
first, http://freshmeat.net/projects/bashdiff/
then, http://home.eol.ca/~parkw/index.html#bash (homepage)
then, http://home.eol.ca/~parkw/bash.diff

Next feature I'll tackle is list comprehension. :-)

--
William Park, Open Geometry Consulting, <op**********@yahoo.ca>
Toronto, Ontario, Canada
Jul 18 '05 #4
In article <2n************@uni-berlin.de>,
William Park <op**********@yahoo.ca> wrote:
....
Next feature I'll tackle is list comprehension. :-)


Are you saying that you don't understand how lists work?
If so, post an item here - I'm sure people will be more than willing to help.

Jul 18 '05 #5
William Park wrote:
try
echo a
raise 2
echo b
done in
0) echo okey ;;
1) echo raised 1 ;;
2) echo raised 2 ;;
*) echo really bad ;;
esac


try...done...esac? What a delightfully eclectic combination
of syntax. :-)

Why doesn't it end with 'yrt'?

--
Greg Ewing, Computer Science Dept,
University of Canterbury,
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg
Jul 18 '05 #6
In <comp.unix.shell> Greg Ewing <gr**@cosc.canterbury.ac.nz> wrote:
William Park wrote:
try
echo a
raise 2
echo b
done in
0) echo okey ;;
1) echo raised 1 ;;
2) echo raised 2 ;;
*) echo really bad ;;
esac


try...done...esac? What a delightfully eclectic combination
of syntax. :-)

Why doesn't it end with 'yrt'?


'try-done' was chosen because it resembles while-loop where you would
break out of; and, '-in-esac' was chosen because it resembles case
statement. Also, I didn't want to introduce too many new keywords.

--
William Park, Open Geometry Consulting, <op**********@yahoo.ca>
Toronto, Ontario, Canada
Jul 18 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by John Bowling | last post: by
reply views Thread by William Park | last post: by
4 posts views Thread by Tom Purl | last post: by
1 post views Thread by Stelios Xanthakis | last post: by
3 posts views Thread by William Park | last post: by
reply views Thread by Kurt B. Kaiser | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.