Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

what exception should I catch for disk full?

Posted on 2008-06-18
4
Medium Priority
?
1,505 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

618 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