aboutsummaryrefslogtreecommitdiff
path: root/tests/try.test
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2010-03-03 15:50:50 +1000
committerSteve Bennett <steveb@workware.net.au>2010-10-15 11:02:48 +1000
commit6a9fcd338b28fe76cb980867632068dd2bec533c (patch)
tree7e4046bd5d6ae0fa018dcfc51208c010b00ef472 /tests/try.test
parentec3d0d6cfddfa055d00c820a2ed99a7d6858aa82 (diff)
downloadjimtcl-6a9fcd338b28fe76cb980867632068dd2bec533c.zip
jimtcl-6a9fcd338b28fe76cb980867632068dd2bec533c.tar.gz
jimtcl-6a9fcd338b28fe76cb980867632068dd2bec533c.tar.bz2
Improvements to catch, return, signal, try
Improve the ability to rethrow errors * Allow return to rethrow an error by accepting '-errorinfo stacktrace' * Also, 'catch ... opts' now also stores opts(-errorinfo) on error * Use these to provide better stack traces from 'case' and 'try' * Implement 'return -level' Make try/on/finally more Tcl 8.6 compatible * With support for 'on' handlers and docs Add support for catch options to try * Otherwise it's hard to use try to catch signals Improvements to signal handling * catch -signal now sets a list of the handled signals as the result * catch -signal won't execute the body at all if a handled signal is pending * up to 64 (jim_wide) signals can now be handled * if catch -signal is nested, the innermost catch will catch the error * new 'signal catch' allows ignored/blocked signals to be examined and cleared. * update docs on signal handling exec should indicate which signal killed the child Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'tests/try.test')
-rw-r--r--tests/try.test47
1 files changed, 46 insertions, 1 deletions
diff --git a/tests/try.test b/tests/try.test
index 3cc86fb..7435763 100644
--- a/tests/try.test
+++ b/tests/try.test
@@ -40,7 +40,7 @@ test try-1.4 "Error in both" {
error finally
}
} msg] $msg $x
-} {1 message 1}
+} {1 finally 1}
test try-1.5 "break in body" {
list [catch {
@@ -63,3 +63,48 @@ test try-1.6 "break in finally" {
}
} msg] $msg $x
} {3 {} 1}
+
+test try-1.7 "return value from try, not finally" {
+ list [catch {
+ try {
+ set x 0
+ } finally {
+ incr x
+ }
+ } msg] $msg $x
+} {0 0 1}
+
+test try-1.8 "return from within try" {
+ proc a {} {
+ try {
+ return 1
+ }
+ # notreached
+ return 2
+ }
+ a
+} {1}
+
+test try-1.9 "return -code from within try" {
+ proc a {} {
+ try {
+ return -code break text
+ }
+ # notreached
+ return 2
+ }
+ list [catch a msg] $msg
+} {3 text}
+
+proc c {} {
+ try {
+ error here
+ } on error {msg opts} {
+ incr opts(-level)
+ return {*}$opts $msg
+ }
+}
+
+test try-3.1 "rethrow error in try/on handler" {
+ list [catch c msg] $msg
+} {1 here}