PC Review


Reply
Thread Tools Rate Thread

Catching exceptions during DirectoryInfo.GetFiles?

 
 
Olaf Rabbachin
Guest
Posts: n/a
 
      6th Apr 2005
Hi folks,

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
 
Reply With Quote
 
 
 
 
Mattias Sjögren
Guest
Posts: n/a
 
      6th Apr 2005
>Any suggestions?

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.



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
 
Reply With Quote
 
Olaf Rabbachin
Guest
Posts: n/a
 
      7th Apr 2005
Hi,

Mattias Sjögren wrote:

>>Any suggestions?

>
> 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.


thanks.
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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Q: DirectoryInfo.GetFiles Martin Arvidsson, Visual Systems AB Microsoft C# .NET 1 17th Apr 2007 04:07 PM
Directory.GetFiles() / DirectoryInfo.GetFiles() on a remote server =?Utf-8?B?RGFuaWVsIENvcnLDqmE=?= Microsoft ASP .NET 2 24th Mar 2007 06:59 PM
DirectoryInfo.GetFiles CJ Taylor Microsoft VB .NET 5 4th Nov 2003 05:27 PM
DirectoryInfo.GetFiles() Pluto Microsoft C# .NET 4 9th Oct 2003 03:49 AM
DirectoryInfo.GetFiles Paul K Microsoft Dot NET Framework 5 31st Jul 2003 11:05 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:04 PM.