none
Handling disk space exception RRS feed

  • Question

  • Hi,

    I am reading files in a folder and copying the files to some other folder.

    I would liketo know how I can handle "Dispk out of space' exception during this process using try/catch block.

    Please help me on this!

    try

    {

    ......................

    ........................

    }

    catch(Exception ex)

    {

    }

    Thursday, April 4, 2013 5:58 AM

Answers

  • Probably it has sense to report more kinds of disk failures. In this case catch the IOException class before catching Exception.

    This will cover the “no space” errors. If you want to detect this particular situation, then get an error code from IOException using ‘unchecked((ushort)Marshal.GetHRForException(exc))’. Then analyse the code according to this table: http://msdn.microsoft.com/en-us/library/windows/desktop/ms681381(v=vs.85).aspx. It seems that you should detect 0x27 and 0x70.

    • Edited by Viorel_MVP Thursday, April 4, 2013 8:37 AM
    • Proposed as answer by Kelmen Friday, April 5, 2013 8:52 AM
    • Marked as answer by Mike FengModerator Tuesday, April 9, 2013 2:51 PM
    Thursday, April 4, 2013 8:24 AM