How can I check if IOException is a “Not enough disk space” exception type?
At the moment I check to see if the message matches something like “Not enough disk space”, but I know that this won’t work if the OS language is not English.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You need to check the
HResultand test against ERROR_DISK_FULL (0x70) and ERROR_HANDLE_DISK_FULL (0x27), which can be converted toHResultsbyOR‘ing with0x80070000.For .Net Framework 4.5 and above, you can use the
Exception.HResultproperty:For older versions, you can use
Marshal.GetHRForExceptionto get back the HResult, but this has significant side-effects and is not recommended:From the MSDN documentation:
See also How do I determine the HResult for a System.IO.IOException?