1try:
2    from esp32 import Partition as p
3    import micropython
4except ImportError:
5    print("SKIP")
6    raise SystemExit
7
8# try some vanilla OSError to get std error code
9try:
10    open("this filedoesnotexist", "r")
11    print("FAILED TO RAISE")
12except OSError as e:
13    print(e)
14
15# try to make nvs partition bootable, which ain't gonna work
16part = p.find(type=p.TYPE_DATA)[0]
17fun = p.set_boot
18try:
19    fun(part)
20    print("FAILED TO RAISE")
21except OSError as e:
22    print(e)
23
24# same but with out of memory condition by locking the heap
25exc = "FAILED TO RAISE"
26micropython.heap_lock()
27try:
28    fun(part)
29except OSError as e:
30    exc = e
31micropython.heap_unlock()
32print("exc:", exc)  # exc empty due to no memory
33
34# same again but having an emergency buffer
35micropython.alloc_emergency_exception_buf(256)
36exc = "FAILED TO RAISE"
37micropython.heap_lock()
38try:
39    fun(part)
40except Exception as e:
41    exc = e
42micropython.heap_unlock()
43print(exc)
44