|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Catching exceptions during DirectoryInfo.GetFiles?I'm copying files from i.e. a memory-card to the hard-drive. The code roughly looks like this abstract: Dim di As New DirectoryInfo("E:\") Dim fi As FileInfo Try For Each fi In di.GetFiles '... Next Catch ... End Try I would've expected that the above code would catch all exceptions, including i.e. the one thrown if the user retracts the memory-card during the process. However, if the disk is removed during di.GetFiles I'll get a standard messagebox "There is no disk in the drive. Please insert a disk into drive \Device\Harddisk1\DR3" and the Catch-block will be executed after the user clicked any of the messagebox's buttons. That's exactly what shouldn't ever happen. Any suggestions? TIA & cheers, Olaf >Any suggestions? You can get rid of the dialog box by calling the Win32 APISetErrorMode. I don't think there's any managed equivalent for that. Mattias -- Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup. Hi,
Mattias Sjögren wrote: >>Any suggestions? thanks.> > You can get rid of the dialog box by calling the Win32 API > SetErrorMode. I don't think there's any managed equivalent for that. But the whole problem really gives me the creeps in general as the existance of that behaviour really renders try/catch useless if there's (fundamental!) functions within the CLR that implement their own error-handling without the chance to have the caller take care of that. Cheers, Olaf |
|||||||||||||||||||||||