diff --git a/dowhy/causal_identifier/id_identifier.py b/dowhy/causal_identifier/id_identifier.py index db8af1bff..5ef8a515d 100644 --- a/dowhy/causal_identifier/id_identifier.py +++ b/dowhy/causal_identifier/id_identifier.py @@ -125,7 +125,7 @@ def identify_effect_id( try: tsort_node_names = OrderedSet(list(nx.topological_sort(graph))) # topological sorting of graph nodes - except: + except nx.NetworkXUnfeasible: raise Exception("The graph must be a directed acyclic graph (DAG).") return __adjacency_matrix_identify_effect( diff --git a/dowhy/utils/graph_operations.py b/dowhy/utils/graph_operations.py index 030a0fd10..73d6370ce 100644 --- a/dowhy/utils/graph_operations.py +++ b/dowhy/utils/graph_operations.py @@ -241,7 +241,7 @@ def find_predecessor(i, j, g): try: path = shortest_path(u, pa, i) return pa - except: + except nx.NetworkXNoPath: pass return None