Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: `try' syntax



Peter wrote:
> Oliver Kiddle wrote:
> > What exactly do break, continue and return do here? Are they unchanged,
> > expecting an enclosing loop or function. 
> 
> Yes.  The description in the manual is supposed to say that.

The manual description should probably also mention exit along with
break, continue and return.

What happens if break, continue, return or exit are used within the
always block?

> > Or how about using special variable which
> > indicates what the "error condition" is and have that be unset.
> 
> Yes, that's possible, and it allows you to test for an error, too, which
> the current syntax doesn't.  Again, I couldn't think of a good name
> which didn't potentially clash with a user variable.  Perhaps TRY_ERROR
> or even TRY_BLOCK_ERROR would be good enough.  (It's not a status;
> $? correctly indicates the status after the try block, but not whether
> an error occurred.)

TRY_ERROR sounds fine though I might go for TRY_STATUS if it can
indicate a lack of error. Testing for an error could certainly be
useful. Does $? get unchanged by the always block like with a trap or
is that only if return or exit is used with an explicit status.

> (I wonder if it could be setable inside the try block to force errflag
> to 1, forcing the rest of the block to be skipped?  That would give a
> nice interaction with traps.  This is getting dangerously close to
> `throw'.)

That's an interesting idea. Would be useful. Having a variable
assignment affect control flow would be more than a bit weird, though.
And without making TRY_ERROR an array, you couldn't skip out of nested
try blocks.

> > The colons make them look like labels.
> 
> Not in any UNIX shell I've ever seen.

DOS batch files have labels in that form and given their lack of any
decent control flow statements, you need to use gotos a lot in them. It
also isn't so dissimilar to other languages' (including the C shell)
use of a trailing colon for labels or named blocks. So when I look at
them, I think label.

Oliver



Messages sorted by: Reverse Date, Date, Thread, Author