Commits

Jason R. Coombs  committed 95b5737

Allow multiple exceptions in throws_exception

  • Participants
  • Parent commits a58083f

Comments (0)

Files changed (1)

File jaraco/util/exceptions.py

 from __future__ import unicode_literals
 
-def throws_exception(callable, exception=Exception):
+def throws_exception(callable, *exceptions):
 	"""
 	Return True if the callable throws the specified exception
 
 	>>> throws_exception(lambda: int('a'), KeyError)
 	False
 	"""
+	if not exceptions: exceptions = Exception,
 	try:
 		callable()
-	except exception:
+	except exceptions:
 		return True
 	except Exception:
 		pass
 	...
 	ValueError: invalid literal for int() with base 10: 'a'
 	"""
-	if not exceptions: exceptions = (Exception,)
+	if not exceptions: exceptions = Exception,
 	try:
 		return callable()
 	except exceptions: