PC Review


Reply
Thread Tools Rate Thread

How to check which IO.Exception it was?

 
 
André Nogueira
Guest
Posts: n/a
 
      23rd Aug 2004
Hi there!
I am developing an Windows Explorer-like application that will tell you the
size of any folder.
But so far I have come across some problems.
For instance, you may not have access to all folders in NTFS drives, or a
floppy disk may not be in the drive when I access it.
The question is, how can I check in a Try Catch statement the precise error
that was returned?
Isn't there an error number? I could check the ex.Message but I believe that
isn't the best way to do it...
How can I check the error number or something?

Thank you!


 
Reply With Quote
 
 
 
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      23rd Aug 2004
* "André Nogueira" <(E-Mail Removed)> scripsit:
> I am developing an Windows Explorer-like application that will tell you the
> size of any folder.
> But so far I have come across some problems.
> For instance, you may not have access to all folders in NTFS drives, or a
> floppy disk may not be in the drive when I access it.
> The question is, how can I check in a Try Catch statement the precise error
> that was returned?
> Isn't there an error number? I could check the ex.Message but I believe that
> isn't the best way to do it...
> How can I check the error number or something?


Take a look at the exception's 'HResult'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
 
Reply With Quote
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      23rd Aug 2004
André,
Have you tried checking for one of the exception classes that inherit from
IOException?

System.Object
System.Exception
System.SystemException
System.IO.IOException
System.IO.DirectoryNotFoundException
System.IO.EndOfStreamException
System.IO.FileLoadException
System.IO.FileNotFoundException
System.IO.PathTooLongException

Remember that most exceptions have a specific Exception class that you can
check for.

Try
' do something
Catch ex As DirectoryNotFoundException
' do something because the directory was not found
Catch ex As FileNotFoundException
' do something because the file was not found
Catch ex As PathTooLongException
' do something because the path was too long
Catch ex As IOException
' do something because a different IO exception occurred
Catch ex As Exception
' generally I would not catch Exception here
' rather I let my global exception handlers deal with
System.Exception
' included more to show proper order of catching exceptions...
End Try

When you catch exceptions as above, be certain to catch the more specific
(most derived) exceptions first, and catch more general (base) exceptions
last.

NOTE: not having access to an NTFS drive may be a security exception instead
of an IO exception, I have not tested it to see which is raised. I either
check my exception log (that my global exception handler wrote) or I
temporarily add a "Catch ex As Exception" and look at what exception was
caught. Instead of temporarily adding a "Catch ex As Exception", the
debugger can break on the exception so you can identify it.

Hope this helps
Jay

"André Nogueira" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi there!
> I am developing an Windows Explorer-like application that will tell you

the
> size of any folder.
> But so far I have come across some problems.
> For instance, you may not have access to all folders in NTFS drives, or a
> floppy disk may not be in the drive when I access it.
> The question is, how can I check in a Try Catch statement the precise

error
> that was returned?
> Isn't there an error number? I could check the ex.Message but I believe

that
> isn't the best way to do it...
> How can I check the error number or something?
>
> Thank you!
>
>



 
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
Machine Check Exception Falcon Windows Vista Performance 0 6th Apr 2009 01:29 PM
Which CHECK constraint causes the exception? ferg Microsoft C# .NET 3 21st May 2006 09:38 PM
Machine Check Exception 9c Andrew Windows XP Help 2 11th Aug 2005 07:09 AM
Machine Check Exception 9c Andrew Windows XP Hardware 1 11th Aug 2005 05:43 AM
Machine Check Exception 9c Andrew Windows XP Hardware 6 8th Aug 2005 10:30 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:48 AM.