Hi,<div><br></div><div>I was working on an extension to SymPy that would allow us to automatically construct missing symbols in interactive isympy sessions (IPython based) (see here [1]) and I found some confusing to me code in IPython/core/interactiveshell.py. The docstring of InteractiveShell.set_custom_exc says that `handler` argument must be a function that returns a structured traceback. However, in InteractiveShell.run_code the code for handling custom exceptions simply calls self.CustomTB(...) and ignores the result [2]. This code also shadows custom exception handling code from InteractiveShell.showtraceback, which doesn't ignore return value from self.CustomTB(), but contains undefined variable `ctb` [3] (should be `stb`).</div>
<div><br></div><div>I wanted to submit a pull request fixing this, but I'm not sure how to proceed. I wanted to remove custom exception handling code from InteractiveShell.run_code and in InteractiveShell.showtraceback add a case for None return value from self.CustomTB(...) (which would mean "do nothing and return immediately", to maintain compatibility), and of course fix `ctb`. I was also thinking about another special case where custom exception handler decides that IPython should proceed with displaying a traceback (False return value would be used for this). This would be useful in my case, because I don't want to do any traceback formatting in the handler, just construct and injects symbols if necessary.</div>
<div><br></div><div>btw. If you see a better way to solve the problem that is solved by [1], I'm looking forward to your suggestions.  </div><div><br></div><div>Mateusz</div><div><br></div><div>[1] <a href="https://github.com/sympy/sympy/pull/643">https://github.com/sympy/sympy/pull/643</a></div>
<div>[2] <a href="https://github.com/ipython/ipython/blob/master/IPython/core/interactiveshell.py#L2438">https://github.com/ipython/ipython/blob/master/IPython/core/interactiveshell.py#L2438</a></div><div>[3] <a href="https://github.com/ipython/ipython/blob/master/IPython/core/interactiveshell.py#L1562">https://github.com/ipython/ipython/blob/master/IPython/core/interactiveshell.py#L1562</a></div>