Show More
@@ -1703,23 +1703,20 b' class InteractiveShell(SingletonConfigurable):' | |||
|
1703 | 1703 | elif etype is UsageError: |
|
1704 | 1704 | self.write_err("UsageError: %s" % value) |
|
1705 | 1705 | else: |
|
1706 |
if |
|
|
1707 | stb = self.CustomTB(etype, value, tb, tb_offset) | |
|
1706 | if exception_only: | |
|
1707 | stb = ['An exception has occurred, use %tb to see ' | |
|
1708 | 'the full traceback.\n'] | |
|
1709 | stb.extend(self.InteractiveTB.get_exception_only(etype, | |
|
1710 | value)) | |
|
1708 | 1711 | else: |
|
1709 | if exception_only: | |
|
1710 | stb = ['An exception has occurred, use %tb to see ' | |
|
1711 | 'the full traceback.\n'] | |
|
1712 | stb.extend(self.InteractiveTB.get_exception_only(etype, | |
|
1713 | value)) | |
|
1714 |
|
|
|
1715 | stb = self.InteractiveTB.structured_traceback(etype, | |
|
1716 | value, tb, tb_offset=tb_offset) | |
|
1717 | ||
|
1718 | self._showtraceback(etype, value, stb) | |
|
1719 | if self.call_pdb: | |
|
1720 | # drop into debugger | |
|
1721 | self.debugger(force=True) | |
|
1722 | return | |
|
1712 | stb = self.InteractiveTB.structured_traceback(etype, | |
|
1713 | value, tb, tb_offset=tb_offset) | |
|
1714 | ||
|
1715 | self._showtraceback(etype, value, stb) | |
|
1716 | if self.call_pdb: | |
|
1717 | # drop into debugger | |
|
1718 | self.debugger(force=True) | |
|
1719 | return | |
|
1723 | 1720 | |
|
1724 | 1721 | # Actually show the traceback |
|
1725 | 1722 | self._showtraceback(etype, value, stb) |
@@ -337,6 +337,21 b' class InteractiveShellTestCase(unittest.TestCase):' | |||
|
337 | 337 | namespace = 'IPython internal', obj= cmagic.__wrapped__, |
|
338 | 338 | parent = None) |
|
339 | 339 | nt.assert_equal(find, info) |
|
340 | ||
|
341 | def test_custom_exception(self): | |
|
342 | called = [] | |
|
343 | def my_handler(shell, etype, value, tb, tb_offset=None): | |
|
344 | called.append(etype) | |
|
345 | shell.showtraceback((etype, value, tb), tb_offset=tb_offset) | |
|
346 | ||
|
347 | ip.set_custom_exc((ValueError,), my_handler) | |
|
348 | try: | |
|
349 | ip.run_cell("raise ValueError('test')") | |
|
350 | # Check that this was called, and only once. | |
|
351 | self.assertEqual(called, [ValueError]) | |
|
352 | finally: | |
|
353 | # Reset the custom exception hook | |
|
354 | ip.set_custom_exc((), None) | |
|
340 | 355 | |
|
341 | 356 | |
|
342 | 357 | class TestSafeExecfileNonAsciiPath(unittest.TestCase): |
General Comments 0
You need to be logged in to leave comments.
Login now