mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-01-01 05:16:05 +01:00
21779 plus unposted catch change: exception improvementss
This commit is contained in:
parent
c3ca181fbe
commit
81a331a3ea
4 changed files with 12 additions and 5 deletions
|
@ -1,3 +1,9 @@
|
|||
2005-09-28 Peter Stephenson <pws@csr.com>
|
||||
|
||||
* 21779: Doc/Zsh/contrib.yo, Functions/Exceptions/throw, plus
|
||||
unposted Functions/Exceptions/catch: improvements from Bart in
|
||||
users/9452 plus clarifications to documentation.
|
||||
|
||||
2005-09-28 Clint Adams <clint@zsh.org>
|
||||
|
||||
* 21778: Completion/Debian/Command/_piuparts: completion for
|
||||
|
|
|
@ -1284,8 +1284,8 @@ example({
|
|||
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
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
function catch {
|
||||
if [[ $TRY_BLOCK_ERROR -gt 0 && $EXCEPTION = ${~1} ]]; then
|
||||
(( TRY_BLOCK_ERROR = 0 ))
|
||||
CAUGHT="$EXCEPTION"
|
||||
typeset -g CAUGHT="$EXCEPTION"
|
||||
unset EXCEPTION
|
||||
return 0
|
||||
fi
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue