MCPcopy Create free account
hub / github.com/ActiveState/code / throws

Function throws

recipes/Python/252530_ExceptiHandling/recipe-252530.py:1–8  ·  view source on GitHub ↗

Return True if f(*a,**k) raises an exception.

(f, *a, **k)

Source from the content-addressed store, hash-verified

1def throws(f, *a, **k):
2 "Return True if f(*a,**k) raises an exception."
3 try:
4 f(*a,**k)
5 except:
6 return True
7 else:
8 return False
9
10
11# Example - get numbers from a file, ignoring ill-formatted ones.

Callers 1

recipe-252530.pyFile · 0.70

Calls 1

fFunction · 0.50

Tested by

no test coverage detected