(patch for Bash) try-block and exception

Discussion in 'Python' started by William Park, Jul 31, 2004.

  1. William Park

    William Park Guest

    (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, <>
    Toronto, Ontario, Canada
     
    William Park, Jul 31, 2004
    #1
    1. Advertising

  2. William Park

    William Park Guest

    In <comp.unix.shell> William Park <> 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, <>
    Toronto, Ontario, Canada
     
    William Park, Jul 31, 2004
    #2
    1. Advertising

  3. William Park

    Harry Putnam Guest

    Harry Putnam, Aug 1, 2004
    #3
  4. William Park

    William Park Guest

    In <comp.lang.python> Harry Putnam <> wrote:
    > William Park <> 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, <>
    Toronto, Ontario, Canada
     
    William Park, Aug 1, 2004
    #4
  5. In article <>,
    William Park <> 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.
     
    Kenny McCormack, Aug 1, 2004
    #5
  6. William Park

    Greg Ewing Guest

    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
     
    Greg Ewing, Aug 2, 2004
    #6
  7. William Park

    William Park Guest

    In <comp.unix.shell> Greg Ewing <> 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, <>
    Toronto, Ontario, Canada
     
    William Park, Aug 2, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. William Park

    (patch for Bash) GTK+2 + Bash

    William Park, Jul 11, 2005, in forum: XML
    Replies:
    3
    Views:
    2,320
    William Park
    Jul 14, 2005
  2. William Park
    Replies:
    0
    Views:
    598
    William Park
    Aug 2, 2004
  3. morrell
    Replies:
    1
    Views:
    990
    roy axenov
    Oct 10, 2006
  4. Karlo Lozovina
    Replies:
    10
    Views:
    391
    Matthew Trevor
    May 23, 2008
  5. George Sakkis
    Replies:
    3
    Views:
    389
Loading...

Share This Page