Improved error handling in WaitForProcEx function.