def on_raised(callback, *args):
    """Invoke callback if exception within args occurs. Reraise exception."""
    def decorator(main_function):
        def wrapper(*wargs, **kwargs):
            try:
                return main_function(*wargs, **kwargs)
            except Exception as e:
                if len(args) == 0 or isinstance(e, args):
                    callback(main_function, e)
                raise e
        return wrapper
    return decorator