Solved

what exception should I catch for disk full?

Posted on 2008-06-18
4
1,365 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Convert string to date 3 40
Hovering effect 9 29
Create XML 5 33
what technologies offer Authentication over Web Services? 4 70
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

705 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now