File tree Expand file tree Collapse file tree 4 files changed +39
-2
lines changed Expand file tree Collapse file tree 4 files changed +39
-2
lines changed Original file line number Diff line number Diff line change @@ -1456,10 +1456,19 @@ unwind_jump:;
1456
1456
// catch exception and pass to byte code
1457
1457
code_state -> ip = exc_sp -> handler ;
1458
1458
mp_obj_t * sp = MP_TAGPTR_PTR (exc_sp -> val_sp );
1459
+ #if MICROPY_CPYTHON_EXCEPTION_CHAIN
1460
+ mp_obj_t active_exception = get_active_exception (exc_sp , exc_stack );
1461
+ #endif
1459
1462
// save this exception in the stack so it can be used in a reraise, if needed
1460
1463
exc_sp -> prev_exc = nlr .ret_val ;
1464
+ mp_obj_t obj = MP_OBJ_FROM_PTR (nlr .ret_val );
1465
+ #if MICROPY_CPYTHON_EXCEPTION_CHAIN
1466
+ if (active_exception != MP_OBJ_NULL ) {
1467
+ mp_store_attr (obj , MP_QSTR___context__ , active_exception );
1468
+ }
1469
+ #endif
1461
1470
// push exception object so it can be handled by bytecode
1462
- PUSH (MP_OBJ_FROM_PTR ( nlr . ret_val ) );
1471
+ PUSH (obj );
1463
1472
code_state -> sp = sp ;
1464
1473
1465
1474
#if MICROPY_STACKLESS
Original file line number Diff line number Diff line change 5
5
raise SystemExit
6
6
7
7
def print_exc_info (e ):
8
- print ("exception" , type (e ), repr ( e ) )
8
+ print ("exception" , type (e ), e . args )
9
9
print ("context" , type (e .__context__ ), e .__suppress_context__ )
10
10
print ("cause" , type (e .__cause__ ))
11
11
@@ -44,3 +44,11 @@ def print_exc_info(e):
44
44
raise RuntimeError () from None
45
45
except Exception as e :
46
46
print_exc_info (e )
47
+
48
+ try :
49
+ try :
50
+ raise RuntimeError ()
51
+ except Exception as inner :
52
+ 1 / 0
53
+ except Exception as e :
54
+ print_exc_info (e )
Original file line number Diff line number Diff line change @@ -53,3 +53,11 @@ def print_exc_info(e):
53
53
raise RuntimeError () from None
54
54
except Exception as e :
55
55
print_exc_info (e )
56
+
57
+ try :
58
+ try :
59
+ raise RuntimeError ()
60
+ except Exception as inner :
61
+ 1 / 0
62
+ except Exception as e :
63
+ print_exc_info (e )
Original file line number Diff line number Diff line change @@ -41,3 +41,15 @@ Traceback (most recent call last):
41
41
RuntimeError:
42
42
------------------------------------------------------------------------
43
43
44
+ ------------------------------------------------------------------------
45
+ Traceback (most recent call last):
46
+ File "circuitpython/traceback_test_chained.py", line 59, in <module>
47
+ RuntimeError:
48
+
49
+ During handling of the above exception, another exception occurred:
50
+
51
+ Traceback (most recent call last):
52
+ File "circuitpython/traceback_test_chained.py", line 61, in <module>
53
+ ZeroDivisionError: division by zero
54
+ ------------------------------------------------------------------------
55
+
You can’t perform that action at this time.
0 commit comments