Solved

what exception should I catch for disk full?

Posted on 2008-06-18
4
1,460 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
[X]
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
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

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!
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

707 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