IPython 8.4.0 Pypi GitHub Homepage
Other Docs
NotesParameters
set_custom_exc(exc_tuple, handler)

Notes

WARNING: by putting in your own exception handler into IPython's main execution loop, you run a very good chance of nasty crashes. This facility should only be used if you really know what you are doing.

Parameters

exc_tuple : tuple of exception classes

A tuple of exception classes, for which to call the defined handler. It is very important that you use a tuple, and NOT A LIST here, because of the way Python's except statement works. If you only want to trap a single exception, use a singleton tuple:

exc_tuple == (MyCustomException,)
handler : callable

handler must have the following signature:

def my_handler(self, etype, value, tb, tb_offset=None):
    ...
    return structured_traceback

Your handler must return a structured traceback (a list of strings), or None.

This will be made into an instance method (via types.MethodType) of IPython itself, and it will be called if any of the exceptions listed in the exc_tuple are caught. If the handler is None, an internal basic one is used, which just prints basic info.

To protect IPython from crashes, if your handler ever raises an exception or returns an invalid result, it will be immediately disabled.

Set a custom exception handler, which will be called if any of the exceptions in exc_tuple occur in the mainloop (specifically, in the run_code() method).

Examples

See :

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /IPython/core/interactiveshell.py#1778
type: <class 'function'>
Commit: