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

Re: About zsh-users 8489 (exception handling)



Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> I think EXCEPTION should also be declared with "typeset -g", so that
> makes the complete function look like:
> 
> throw() {
>   typeset -g EXCEPTION="$1"
>   readonly THROW
>   if (( TRY_BLOCK_ERROR == 0 )); then
>     # We are throwing an exception from the middle of an always-block.
>     # We can do this by restoring the error status from the try-block.
>     # (I am not convinced I ever intended this to work, but it does...)
>     (( TRY_BLOCK_ERROR = 1 ))
>   fi
>   # Raise an error, but don't show an error message.
>   # This is a bit of a hack.  (Surprised?)
>   THROW= 2>/dev/null
> }

How about this...

Index: Doc/Zsh/contrib.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/contrib.yo,v
retrieving revision 1.47
diff -u -r1.47 contrib.yo
--- Doc/Zsh/contrib.yo	22 Sep 2005 22:23:45 -0000	1.47
+++ Doc/Zsh/contrib.yo	28 Sep 2005 15:16:36 -0000
@@ -1284,8 +1284,8 @@
 In common with exception handling in other languages, the exception may be
 thrown by code deeply nested inside the `try' block.  However, note that it
 must be thrown inside the current shell, not in a subshell forked for a
-pipline, parenthesised current-shell construct, or some form of
-substitution.
+pipeline, parenthesised current-shell construct, or some form of
+command or process substitution.
 
 The system internally uses the shell variable tt(EXCEPTION) to record the
 name of the exception between throwing and catching.  One drawback of this
Index: Functions/Exceptions/throw
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/Exceptions/throw,v
retrieving revision 1.1
diff -u -r1.1 throw
--- Functions/Exceptions/throw	15 Feb 2005 18:32:38 -0000	1.1
+++ Functions/Exceptions/throw	28 Sep 2005 15:16:36 -0000
@@ -19,11 +19,12 @@
 # script.
 
 # The following must not be local.
-EXCEPTION="$1"
+typeset -g EXCEPTION="$1"
+readonly THROW
 if (( TRY_BLOCK_ERROR == 0 )); then
   # We are throwing an exception from the middle of an always-block.
   # We can do this by restoring the error status from the try-block.
   (( TRY_BLOCK_ERROR = 1 ))
 fi
 # Raise an error, but don't show an error message.
-{ ${:?THROW} } 2>/dev/null
+THROW= 2>/dev/null



-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

**********************************************************************



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