(patch for Bash) try-block and exception

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • William Park

    (patch for Bash) try-block and exception

    (crossposted to comp.lang.pytho n, 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:
    Free, secure and fast downloads from the largest Open Source applications and software directory - SourceForge.net

    help try
    help raise

    --
    William Park, Open Geometry Consulting, <opengeometry@y ahoo.ca>
    Toronto, Ontario, Canada
  • William Park

    #2
    Re: (patch for Bash) try-block and exception

    In <comp.unix.shel l> William Park <opengeometry@y ahoo.ca> wrote:[color=blue]
    > (crossposted to comp.lang.pytho n, 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[/color]

    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
    [color=blue]
    >
    > 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[/color]

    --
    William Park, Open Geometry Consulting, <opengeometry@y ahoo.ca>
    Toronto, Ontario, Canada

    Comment

    • Harry Putnam

      #3
      Re: (patch for Bash) try-block and exception

      William Park <opengeometry@y ahoo.ca> writes:
      [color=blue][color=green]
      >> Ref:
      >> http://freshmeat.net/projects/bashdiff/
      >> help try
      >> help raise[/color][/color]

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

      Comment

      • William Park

        #4
        Re: (patch for Bash) try-block and exception

        In <comp.lang.pyth on> Harry Putnam <reader@newsguy .com> wrote:[color=blue]
        > William Park <opengeometry@y ahoo.ca> writes:
        >[color=green][color=darkred]
        > >> Ref:
        > >> http://freshmeat.net/projects/bashdiff/
        > >> help try
        > >> help raise[/color][/color]
        >
        > This link doesn't appear to lead to a `download' option..[/color]

        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, <opengeometry@y ahoo.ca>
        Toronto, Ontario, Canada

        Comment

        • Kenny McCormack

          #5
          Re: (patch for Bash) try-block and exception

          In article <2n3jliFrvv9dU1 @uni-berlin.de>,
          William Park <opengeometry@y ahoo.ca> wrote:
          ....[color=blue]
          >Next feature I'll tackle is list comprehension. :-)[/color]

          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.

          Comment

          • Greg Ewing

            #6
            Re: (patch for Bash) try-block and exception

            William Park wrote:[color=blue]
            > try
            > echo a
            > raise 2
            > echo b
            > done in
            > 0) echo okey ;;
            > 1) echo raised 1 ;;
            > 2) echo raised 2 ;;
            > *) echo really bad ;;
            > esac[/color]

            try...done...es ac? 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

            Comment

            • William Park

              #7
              Re: (patch for Bash) try-block and exception

              In <comp.unix.shel l> Greg Ewing <greg@cosc.cant erbury.ac.nz> wrote:[color=blue]
              > William Park wrote:[color=green]
              > > try
              > > echo a
              > > raise 2
              > > echo b
              > > done in
              > > 0) echo okey ;;
              > > 1) echo raised 1 ;;
              > > 2) echo raised 2 ;;
              > > *) echo really bad ;;
              > > esac[/color]
              >
              > try...done...es ac? What a delightfully eclectic combination
              > of syntax. :-)
              >
              > Why doesn't it end with 'yrt'?[/color]

              '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, <opengeometry@y ahoo.ca>
              Toronto, Ontario, Canada

              Comment

              Working...