Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > (patch for Bash) try-block and exception

Reply
Thread Tools

(patch for Bash) try-block and exception

 
 
William Park
Guest
Posts: n/a
 
      07-31-2004
(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, <(E-Mail Removed)>
Toronto, Ontario, Canada
 
Reply With Quote
 
 
 
 
William Park
Guest
Posts: n/a
 
      07-31-2004
In <comp.unix.shell> William Park <(E-Mail Removed)> 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, <(E-Mail Removed)>
Toronto, Ontario, Canada
 
Reply With Quote
 
 
 
 
Harry Putnam
Guest
Posts: n/a
 
      08-01-2004
William Park <(E-Mail Removed)> writes:

>> Ref:
>> http://freshmeat.net/projects/bashdiff/
>> help try
>> help raise


This link doesn't appear to lead to a `download' option..
 
Reply With Quote
 
William Park
Guest
Posts: n/a
 
      08-01-2004
In <comp.lang.python> Harry Putnam <(E-Mail Removed)> wrote:
> William Park <(E-Mail Removed)> 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, <(E-Mail Removed)>
Toronto, Ontario, Canada
 
Reply With Quote
 
Kenny McCormack
Guest
Posts: n/a
 
      08-01-2004
In article <(E-Mail Removed)>,
William Park <(E-Mail Removed)> 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.

 
Reply With Quote
 
Greg Ewing
Guest
Posts: n/a
 
      08-02-2004
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
 
Reply With Quote
 
William Park
Guest
Posts: n/a
 
      08-02-2004
In <comp.unix.shell> Greg Ewing <(E-Mail Removed)> 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, <(E-Mail Removed)>
Toronto, Ontario, Canada
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Handle C++ exception and structured exception together George2 C++ 15 01-29-2008 07:34 AM
Is an exception specification needed if the method throws and catchesits own exception? elcapitan666@gmail.com C++ 2 11-27-2007 04:01 AM
Exception of type 'System.Web.HttpUnhandledException' wasthrown.Exception has been thrown by the target of an invocation.System.WebSystem.Exception jobs ASP .Net 1 11-16-2007 05:57 PM
while executing my client program i get the exception javax.naming.LinkException: [Root exception is javax.naming.LinkException: [Root exception is javax.naming.NameNotFoundException: remaining if plz anybody know how to solve this problem then mahesh Java 0 03-08-2007 12:26 PM
how to show C line number AND exception type in JNI exception stacktrace? Elaine Cheong Java 1 12-09-2006 08:59 AM



Advertisments