##// END OF EJS Templates
Fix showing SystemExit exception raise inside except handler (#14503)...
M Bussonnier -
r28830:d5762c16 merge
parent child Browse files
Show More
@@ -298,6 +298,13 b' except Exception:'
298 raise ValueError("Yikes") from None
298 raise ValueError("Yikes") from None
299 """
299 """
300
300
301 SYS_EXIT_WITH_CONTEXT_CODE = """
302 try:
303 1/0
304 except Exception as e:
305 raise SystemExit(1)
306 """
307
301 def test_direct_cause_error(self):
308 def test_direct_cause_error(self):
302 with tt.AssertPrints(["KeyError", "NameError", "direct cause"]):
309 with tt.AssertPrints(["KeyError", "NameError", "direct cause"]):
303 ip.run_cell(self.DIRECT_CAUSE_ERROR_CODE)
310 ip.run_cell(self.DIRECT_CAUSE_ERROR_CODE)
@@ -306,6 +313,11 b' except Exception:'
306 with tt.AssertPrints(["KeyError", "NameError", "During handling"]):
313 with tt.AssertPrints(["KeyError", "NameError", "During handling"]):
307 ip.run_cell(self.EXCEPTION_DURING_HANDLING_CODE)
314 ip.run_cell(self.EXCEPTION_DURING_HANDLING_CODE)
308
315
316 def test_sysexit_while_handling_error(self):
317 with tt.AssertPrints(["SystemExit", "to see the full traceback"]):
318 with tt.AssertNotPrints(["another exception"], suppress=False):
319 ip.run_cell(self.SYS_EXIT_WITH_CONTEXT_CODE)
320
309 def test_suppress_exception_chaining(self):
321 def test_suppress_exception_chaining(self):
310 with tt.AssertNotPrints("ZeroDivisionError"), \
322 with tt.AssertNotPrints("ZeroDivisionError"), \
311 tt.AssertPrints("ValueError", suppress=False):
323 tt.AssertPrints("ValueError", suppress=False):
@@ -552,6 +552,8 b' class ListTB(TBTools):'
552 lines = ''.join(self._format_exception_only(etype, evalue))
552 lines = ''.join(self._format_exception_only(etype, evalue))
553 out_list.append(lines)
553 out_list.append(lines)
554
554
555 # Find chained exceptions if we have a traceback (not for exception-only mode)
556 if etb is not None:
555 exception = self.get_parts_of_chained_exception(evalue)
557 exception = self.get_parts_of_chained_exception(evalue)
556
558
557 if exception and (id(exception[1]) not in chained_exc_ids):
559 if exception and (id(exception[1]) not in chained_exc_ids):
@@ -573,7 +575,8 b' class ListTB(TBTools):'
573 context,
575 context,
574 )
576 )
575 + chained_exception_message
577 + chained_exception_message
576 + out_list)
578 + out_list
579 )
577
580
578 return out_list
581 return out_list
579
582
General Comments 0
You need to be logged in to leave comments. Login now