##// 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 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 308 def test_direct_cause_error(self):
302 309 with tt.AssertPrints(["KeyError", "NameError", "direct cause"]):
303 310 ip.run_cell(self.DIRECT_CAUSE_ERROR_CODE)
@@ -306,6 +313,11 b' except Exception:'
306 313 with tt.AssertPrints(["KeyError", "NameError", "During handling"]):
307 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 321 def test_suppress_exception_chaining(self):
310 322 with tt.AssertNotPrints("ZeroDivisionError"), \
311 323 tt.AssertPrints("ValueError", suppress=False):
@@ -552,28 +552,31 b' class ListTB(TBTools):'
552 552 lines = ''.join(self._format_exception_only(etype, evalue))
553 553 out_list.append(lines)
554 554
555 exception = self.get_parts_of_chained_exception(evalue)
555 # Find chained exceptions if we have a traceback (not for exception-only mode)
556 if etb is not None:
557 exception = self.get_parts_of_chained_exception(evalue)
556 558
557 if exception and (id(exception[1]) not in chained_exc_ids):
558 chained_exception_message = (
559 self.prepare_chained_exception_message(evalue.__cause__)[0]
560 if evalue is not None
561 else ""
562 )
563 etype, evalue, etb = exception
564 # Trace exception to avoid infinite 'cause' loop
565 chained_exc_ids.add(id(exception[1]))
566 chained_exceptions_tb_offset = 0
567 out_list = (
568 self.structured_traceback(
569 etype,
570 evalue,
571 (etb, chained_exc_ids), # type: ignore
572 chained_exceptions_tb_offset,
573 context,
559 if exception and (id(exception[1]) not in chained_exc_ids):
560 chained_exception_message = (
561 self.prepare_chained_exception_message(evalue.__cause__)[0]
562 if evalue is not None
563 else ""
564 )
565 etype, evalue, etb = exception
566 # Trace exception to avoid infinite 'cause' loop
567 chained_exc_ids.add(id(exception[1]))
568 chained_exceptions_tb_offset = 0
569 out_list = (
570 self.structured_traceback(
571 etype,
572 evalue,
573 (etb, chained_exc_ids), # type: ignore
574 chained_exceptions_tb_offset,
575 context,
576 )
577 + chained_exception_message
578 + out_list
574 579 )
575 + chained_exception_message
576 + out_list)
577 580
578 581 return out_list
579 582
General Comments 0
You need to be logged in to leave comments. Login now