How to check if IOException is Not-Enough-Disk-Space-Exception type?

前端 未结 5 1498
被撕碎了的回忆
被撕碎了的回忆 2020-11-28 06:12

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 e

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-28 07:04

    In .NET 4.5, the HResult property getter is now Public, so you do not have to use Marshal.GetHRForException (along with its side affects) anymore.

    http://msdn.microsoft.com/en-us/library/system.exception.hresult(v=vs.110).aspx states "Starting with the .NET Framework 4.5, the HResult property's setter is protected, whereas its getter is public. In previous versions of the .NET Framework, both getter and setter are protected"

    So you can use Justin's answer, but replace Marshal.GetHRForException(ex) with ex.HResult.

提交回复
热议问题