neurokernel.tools.misc.catch_exception

neurokernel.tools.misc.catch_exception(func, disp, *args, **kwargs)[source]

Catch and report exceptions when executing a function.

If an exception occurs while executing the specified function, the exception’s message and the line number where it occurred (in the innermost traceback frame) are displayed.

Examples

>>> import sys
>>> def f(x): x/0
>>> catch_exception(f, sys.stdout.write, 1) 
f: integer division or modulo by zero (...:1)
Parameters:
  • func (function) – Function to execute.
  • disp (function) – Function to use to display exception message.
  • args (list) – Function arguments.
  • kwargs (dict) – Named function arguments.