all Python 3ctypesexception
ctypes.ArgumentError
exceptions
A ctypes exception raised when a foreign function call cannot convert one of the passed arguments; it inherits directly from Exception, not from TypeError.
Syntax
ctypes.ArgumentError
The surprise is that it inherits straight from Exception, so an except TypeError around your foreign call will not catch it — name ctypes.ArgumentError explicitly. It fires while converting one specific argument, and the message tells you which position failed, so read it instead of guessing. The flip side: with no argtypes declared there is nothing to check, and instead of a clean ArgumentError you risk memory corruption or a hard crash of the process.
Examples
import ctypes
print(issubclass(ctypes.ArgumentError, Exception)) # → True
try:
raise ctypes.ArgumentError('argument 1: TypeError')
except ctypes.ArgumentError as e:
print(e) # → argument 1: TypeError
See also
Open in the full glossarydocs.python.orgReport an inaccuracy