def raise_on_error(f):
@functools.wraps(f)<EOL>def wrapper(*args, **kwargs):<EOL><INDENT>result = f(*args, **kwargs)<EOL>retcode = GetLastError()<EOL>if retcode and retcode != ERROR_IO_PENDING:<EOL><INDENT>err = WinError(code=retcode)<EOL>windll.kernel32.SetLastError(<NUM_LIT:0>)  <EOL>raise err<EOL><DEDENT>return result<EOL><DEDENT>return wrapper<EOL>
This decorator throws a WinError whenever GetLastError() returns an error.
As as special case, ERROR_IO_PENDING is ignored.