Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

what exception should I catch for disk full?

Posted on 2008-06-18
4
1,415 Views
Last Modified: 2013-12-16
Hi,
I am writing a windows application using c#. this needs application needs to keep writing csv file. my question is what exception I should catch if system is runing out of disk space.

thanks
0
Comment
Question by:viola123
  • 2
4 Comments
 
LVL 1

Expert Comment

by:CartoonHead
ID: 21819830
You can test available disk space using:
DriveInfo di= new DriveInfo("C:");
long freeSpace = di.TotalFreeSpace;
and the exeption would be IOException.

Probably better to test you have space available before attemting the write though.
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 500 total points
ID: 21819842
You can add the general error, and after you got the right error you can perhaps specify it a little bit better (I'm not sure if there is a specific diskfull-exception)
Example
try
    {
      // We're simply copying a file here.
      System.IO.File.Copy(strFile, strFile + ".new");
    }
    catch (Exception ex)
    {
      Console.WriteLine("Failed to copy the file: " +  ex.Message);
    }
0
 
LVL 18

Expert Comment

by:philipjonathan
ID: 21819888
It should be IOException.
You can test it out easily by writing to a floppy drive or USB thumbdrive (which is near full) ;)
0
 
LVL 18

Expert Comment

by:philipjonathan
ID: 21819910
It should be IOException.
You can test it out easily by writing to a floppy drive or USB thumbdrive (which is near full) ;)

If you are unsure, follow what Dhaest suggested by catching a generic exception and simulate the disk full scenario. Then you can find out the Exception type by putting a breakpoint on the catch line and open your "Watch" panel in VS.
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question