summaryrefslogtreecommitdiff
path: root/tests/micropython/viper_try.py
blob: d75b3418e3d48d367c475dffded6d0ef1f04ce67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# test try handling within a viper function

# basic try-finally
@micropython.viper
def f():
    try:
        fail
    finally:
        print('finally')
try:
    f()
except NameError:
    print('NameError')

# nested try-except with try-finally
@micropython.viper
def f():
    try:
        try:
            fail
        finally:
            print('finally')
    except NameError:
        print('NameError')
f()

# check that locals written to in try blocks keep their values
@micropython.viper
def f():
    a = 100
    try:
        print(a)
        a = 200
        fail
    except NameError:
        print(a)
        a = 300
    print(a)
f()