def wrapped(self, etype, value, tb, tb_offset=None):
    'wrap CustomTB handler, to protect IPython from user code\n\n                This makes it harder (but not impossible) for custom exception\n                handlers to crash IPython.\n                '
    try:
        stb = handler(self, etype, value, tb, tb_offset=tb_offset)
        return validate_stb(stb)
    except:
        self.set_custom_exc((), None)
        print('Custom TB Handler failed, unregistering', file=sys.stderr)
        stb = self.InteractiveTB.structured_traceback(*sys.exc_info())
        print(self.InteractiveTB.stb2text(stb))
        print('The original exception:')
        stb = self.InteractiveTB.structured_traceback((etype, value, tb), tb_offset=tb_offset)
    return stb
wrap CustomTB handler, to protect IPython from user code

This makes it harder (but not impossible) for custom exception
handlers to crash IPython.
def wrapped(self, etype, value, tb, tb_offset=None):
    'wrap CustomTB handler, to protect IPython from user code\n\n                This makes it harder (but not impossible) for custom exception\n                handlers to crash IPython.\n                '
    try:
        stb = handler(self, etype, value, tb, tb_offset=tb_offset)
        return validate_stb(stb)
    except:
        self.set_custom_exc((), None)
        print('Custom TB Handler failed, unregistering', file=sys.stderr)
        stb = self.InteractiveTB.structured_traceback(*sys.exc_info())
        print(self.InteractiveTB.stb2text(stb))
        print('The original exception:')
        stb = self.InteractiveTB.structured_traceback((etype, value, tb), tb_offset=tb_offset)
    return stb