summaryrefslogtreecommitdiff
path: root/tests/run/tryfinally.pyx
diff options
context:
space:
mode:
authorStefan Behnel <scoder@users.berlios.de>2008-12-08 22:22:21 +0100
committerStefan Behnel <scoder@users.berlios.de>2008-12-08 22:22:21 +0100
commit6a08a7805c70ad73087154e945116cd8f4aeb3f0 (patch)
treeeb39c24440c9eaa238c8f0d169b06aabb307d16a /tests/run/tryfinally.pyx
parent69211801670f650d82523b5d01175cc50aa3fded (diff)
downloadcython-6a08a7805c70ad73087154e945116cd8f4aeb3f0.tar.gz
runnable test case for try-finally
Diffstat (limited to 'tests/run/tryfinally.pyx')
-rw-r--r--tests/run/tryfinally.pyx61
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/run/tryfinally.pyx b/tests/run/tryfinally.pyx
new file mode 100644
index 000000000..8caac5d78
--- /dev/null
+++ b/tests/run/tryfinally.pyx
@@ -0,0 +1,61 @@
+u"""
+>>> try:
+... raise ValueError
+... finally:
+... raise TypeError
+Traceback (most recent call last):
+TypeError
+>>> finally_except()
+Traceback (most recent call last):
+TypeError
+
+>>> def try_return_py():
+... try:
+... return 1
+... finally:
+... return 2
+>>> try_return_py()
+2
+>>> try_return_cy()
+2
+
+>>> i=1
+>>> for i in range(3):
+... try:
+... continue
+... finally:
+... i+=1
+>>> i
+3
+>>> try_continue(3)
+3
+"""
+
+def finally_except():
+ try:
+ raise ValueError
+ finally:
+ raise TypeError
+
+def try_return_cy():
+ try:
+ return 1
+ finally:
+ return 2
+
+def try_return_temp(a):
+ b = a+2
+ try:
+ c = a+b
+ return c
+ finally:
+ print b-a
+
+def try_continue(a):
+ i=1
+ for i in range(a):
+ try:
+ continue
+ finally:
+ i+=1
+ return i