← index #1700Issue #290
Off-topic · high · value 0.123
QUERY · ISSUE

Custom exception cannot be re-raised from called function

openby mbueschopened 2015-12-09updated 2026-03-18
docs

Consider this code:

class MyEx(Exception): pass

def do_raise():
        raise

try:
        raise MyEx()
except MyEx:
        try:
                do_raise()
        except MyEx:
                print("Ok")
        else:
                print("not Ok")

On MicroPython it fails with

Traceback (most recent call last):
  File "/home/mb/test.py", line 12, in <module>
  File "/home/mb/test.py", line 10, in <module>
  File "/home/mb/test.py", line 4, in do_raise
RuntimeError: No active exception to reraise

Things I noticed:
If the raise is done directly in the handler instead of do_raise, it works correctly (prints Ok).
If the exception is Exception instead of MyEx, it also works correctly.

CANDIDATE · ISSUE

Throwing exceptions across modules causes namespace issues

closedby pfalconopened 2014-02-14updated 2014-02-16
bug

Testcase:

$ cat submod.py 
def foo():
    raise OSError

$ cat testcase2.py 
import submod

def func1():
    return

def func2():
    try:
        submod.foo()
    except OSError:
        pass
    func1()

func2()

$ micropython testcase2.py 
Traceback (most recent call last):
  File "testcase2.py", line 14, in <module>
  File "testcase2.py", line 11, in func2
NameError: name 'func1' is not defined

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied