Skip to content

Commit

Permalink
macports1.0: Replace and rename try/catch
Browse files Browse the repository at this point in the history
Replace the old try implementation with a BSD-licensed one from tcllib's
try module, and rename it to macports_try. Extend the original tcllib
implementation with our -pass_signal flag.

Note that this commit does not include the required adaptions to users
of the old try implementation for reviewability purposes. These changes
will arrive in a follow-up commit.
  • Loading branch information
neverpanic authored and jmroot committed Sep 7, 2022
1 parent f8dbbc8 commit d7cf914
Show file tree
Hide file tree
Showing 3 changed files with 212 additions and 204 deletions.
52 changes: 16 additions & 36 deletions doc/portfile.7
Expand Up @@ -2727,69 +2727,49 @@ is set to the empty string and the entire former value is returned.
Has the same usage semantics as
.Xr lindex n .
.It Xo
.Ic try
.Ic macports_try
.Op Ar -pass_signal
.Ar body
.Oo
.Nm catch Nm {
.Ar type-list
.Op Ar ecvar
.Op Ar msgvar
.Op Ar infovar
.Nm }
.Ar body Ar \&...
.Ar handler Ar \&...
.Oc
.Op Nm finally Ar body
.Op Nm finally Ar script
.Xc
Implements a try-catch-finally block as defined in TIP #89.
Tcl try block with optional signal pass-thru. When signal pass-thru is not required, use the native try.
.br
.Sy Example:
Basic try-finally construct.
Basic try-finally construct with signal passing.
.Bd -literal -offset indent -compact
try {
macports_try -pass_signal {
set fd [open $file r]
# do stuff here
} finally {
close $fd
}
.Ed
.Sy Example:
Basic try-catch construct
Basic try-on error construct
.Bd -literal -offset indent -compact
try {
macports_try -pass_signal {
set result [expr $num / $div]
} catch {{ARITH DIVZERO}} {
} trap {ARITH DIVZERO} {eMessage eOptions} {
set result -1
}
.Ed
.Sy Example:
Basic try with multiple catches construct
Basic try with multiple handlers construct
.Bd -literal -offset indent -compact
try {
macports_try -pass_signal {
set fd [open $file r]
# do stuff here
} catch {{POSIX ENOENT} {} msgvar} {
puts stderr $msgvar
} catch {*} {
} trap {POSIX ENOENT} {eMessage eOptions} {
puts stderr $eMessage
} on error {_ eOptions} {
puts stderr "An error occurred while processing the file"
close $fd
throw
throw [dict get $eOptions -errorcode] [dict get $eOptions -errorinfo]
}
.Ed
.It Xo
.Ic throw
.Op Ar type
.Op Ar message
.Op Ar info
.Xc
Throws an exception.
If given arguments, works just like
.Ic error
.Ar message
.Ar info
.Ar type .
If called with no arguments from within a
.Ic catch
block, re-throws the caught exception.
.El
.Pp
.Bl -tag -width lc -compact
Expand Down

0 comments on commit d7cf914

Please sign in to comment.