fix to catch an exception in networkx