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

Re: TRY_BLOCK_ERROR and exit status



On Nov 24, 10:11am, Peter Stephenson wrote:
}
} > other hand I think always+TRY_BLOCK_ERROR is the only way lastval can
} > still be examined after errflag has been set, so maybe it would suffice
} > to handle this there?
} 
} Yes, probably.
} 
} > What should the value of lastval ($?) be in this circumstance?
} 
} The easiest way out is probably to leave it if it's non-zero, else set
} it to 1.
} 
} Given that "always" isn't all that widely used, changing it to return
} the last status of the always block might also work.  However, it
} doesn't look necessary to go that far.

Do you mean return the last status of the always block only in the case
where errflag is nonzero at the end of the try block?  If that's not
what you mean, wouldn't that break the current normal use case where
always is for cleaning up whether or not there was an error?

I agree it isn't necessary to go that far.  This?


diff --git a/Src/loop.c b/Src/loop.c
index 2f639fd..82d2fe3 100644
--- a/Src/loop.c
+++ b/Src/loop.c
@@ -659,8 +659,9 @@ exectry(Estate state, int do_exec)
 
     try_tryflag = save_try_tryflag;
 
-    /* Don't record errflag here, may be reset. */
-    endval = lastval;
+    /* Don't record errflag here, may be reset.  However, */
+    /* endval should show failure when there is an error. */
+    endval = lastval ? lastval : errflag;
 
     freeheap();
 



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