I have a ASP.NET application that sits on a server that from time to time gets disk space warnings. Obviously the simplest solution is to get more disk space if policing I/O activity does not work help. But I do not want to edit the registry to change the value that triggers the warning. But the problem is my .NET application throws the disk space warning message. Is there a way to tell the .Net application to ignore this error and continue?
-
Is it an exception? Or what do you mean by error from .Net application? – Sergey Litvinov Jun 18 '14 at 22:36
2 Answers
If .NET throws an error indicating that you are out of disk space, that is more than just a warning. Some code tried to write to disk and failed.
You need to track down what is causing too much disk space to be used. Either optimize the code to use less, handle the situation gracefully if you can not grab enough disk space, or add more hardware.

- 147,927
- 63
- 340
- 553
Whenever you want to ignore an error, you can wrap the call in a try block and swallow the error like this:
try
{
DoSomethingThatCausesAnError();
}
catch
{
//Swallow the exception
}
If at all possible you should only swallow specific errors:
try
{
DoSomethingThatCausesAnError();
}
catch(System.IO.IOException exception)
{
//Swallow the exception
}
Unfortunately it's a little tricky to catch ONLY "drive full" errors. You need to get access to the protected HResult member. For tips on how to do that, click here
P.S. It's probably a really bad idea to do any of this. You really ought to figure out why your system is reporting disk full errors and take care of the root cause.
-
Just swallowing the exception, as you note, is *very* bad practice. It hides the underlying issue, and may lead the user to believe code has run when in fact it has not. – Eric J. Jun 19 '14 at 16:25
-
I agree with John and Eric, we needed to add more disk space. However, I wanted to bypass the error. – user1186256 Jun 19 '14 at 20:15