summaryrefslogtreecommitdiff
path: root/tests/micropython/native_try.py
blob: 6a2152b28c71e8f290fb9e219b2c18871c1a20ae (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
41
42
43
44
45
46
47
48
# test native try handling


# basic try-finally
@micropython.native
def f():
    try:
        fail
    finally:
        print("finally")


try:
    f()
except NameError:
    print("NameError")


# nested try-except with try-finally
@micropython.native
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.native
def f():
    a = 100
    try:
        print(a)
        a = 200
        fail
    except NameError:
        print(a)
        a = 300
    print(a)


f()