Disk Is Full - Which Exception To Catch

  • Thread starter Thread starter Richard
  • Start date Start date
R

Richard

Hi there,

I want to catch a "disk is full" exception on an attempted write.
Ive got the code to check available disk space etc but it's in a
highly iterative loop and i'd rather just catch the exception than
poll the hard drive.

It wouldn't be OutOfMemory 'cause thats RAM and nothing in System.IO
seems to fit the bill..... and i'd rather just ask than fill a hard
drive to simulate.

TIA
Richard
 
* (e-mail address removed) (Richard) scripsit:
I want to catch a "disk is full" exception on an attempted write.
Ive got the code to check available disk space etc but it's in a
highly iterative loop and i'd rather just catch the exception than
poll the hard drive.

Maybe an 'IOException'.
 
Maybe an 'IOException'.

Thanks for the reply.
Yeah i thought that but its a little general. I figured there might be
something more specific.

If its just a write error then I will try to rewrite a couple of times
and then carry on thru the loop but if the disk is full then i want to
exit for and rollback.

Does anyone know what the wording is for disk full exception msg? I
suppose i could always hack at a ex.message comparision?

TIA

Richard
 
Richard,
Does anyone know what the wording is for disk full exception msg? I
suppose i could always hack at a ex.message comparision?

Remember the wording will be localized for the language of the OS you are
running on.

I would not check the ex.Message text to find a specific exception, as this
will hamper any internationalization later, also the wording itself may
change in future versions of the product. I would only rely on the exception
type itself (PathTooLongException verses FileNotFoundException) or
properties of the exception itself (WebException.Status)

I would however consider using ex.Message as text to display to the user, to
enable them to diagnose the problem if I cannot handle it programmically.

Note: WebException.Status is an Enum not a String (text).

Hope this helps
Jay
 
Hi Jay,

Thanks for your reply.
Those are all good points and i agree... but this is just for a little
music backup app for myself so im not too worried about a *hack*

:)

I've got it sorted though. Im a complete moron at the best of times.
If i had haLF a brain I would have thought sooner to just fill a
floppy drive (all i.44MB) of it to get the exception.

But it's been so long since ive used one that i completely forgot i
had one... floppy drive that is ;)

If anyone cares, there is not a specific exception for the Disk Full
condition it IS just good old System.IO.IOException.

Wording is:
There is not enough space on the disk.


Now... does anyone know where i might order a "Stupid is As Stupid
Does" bumper sticker.

Thanks
Richard
 
Richard,
The problem with *hacks* is, that is what they are hacks. If someone ever
picks up your code and starts using it, they may go "Gee Richard does it, so
it must be ok", then suddenly its a company wide standard... ;-)

I would at least put a HACK comment in front of it, so others will know
there should be a better way of doing this, but you have not found it.

HACK comments are similar to TODO comments, both can show up in your Task
List:

Catch ex As IOException
' HACK: We should have a real exception to catch
If ex.Message = "There is not enough space on the disk." Then
' Handle a disk full exception
Else
Throw ' let other IOexceptions Percolate up...
End if

Hope this helps
Jay
 
Good idea but like i say, it's not company code, its just a personal music app.
I just subclassed ApplicationException and threw a custom VolumeIsFullException.

Cheers
Richard
 
Back
Top