try:
raise ExceptionGroup("group", [
ValueError("v1"),
ValueError("v2"),
TypeError("t1")
])
except* ValueError as eg:
print(f"ValueError count: {len(eg.exceptions)}")
except* TypeError as eg:
print(f"TypeError count: {len(eg.exceptions)}") try:
raise ExceptionGroup("group", [
ValueError("v1"),
ValueError("v2"),
TypeError("t1")
])
except* ValueError as eg:
print(f"ValueError count: {len(eg.exceptions)}")
except* TypeError as eg:
print(f"TypeError count: {len(eg.exceptions)}") ValueError count: 2 然后 TypeError count: 1
ValueError count: 2(只匹配第一个except*)
TypeError count: 1(只匹配最后一个except*)
ValueError count: 3