Mike Broderick
asked on
Visual Basic .Net, Need the Specific reason an IOException was thrown.
Is there an equivilant to C's errno in catching an IOException in .Net? I have an app that tests for locks, and I want to make sure I am waiting because the error was a locking problem, not another problem ("Access Denied", etc.). I do not want to parse the error string (could change, not language independent) or retrieve process list and look for my file (too much CPU). Is there a feature of .Net that works like errno?
Thanks.
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try this one:
Try
Throw New IOException()
Catch ex As Exception
Console.WriteLine(Err.Number)
End Try
Try
Throw New IOException()
Catch ex As Exception
Console.WriteLine(Err.Number)
End Try
ASKER
Perfect! Both work. I picked the Err obj. The file locked at open gives 32 and the filestream.Lock() gives 33. They are documented here:
http://msdn.microsoft.com/en-us/library/ms681382(v=VS.85).aspx
Thanks
http://msdn.microsoft.com/en-us/library/ms681382(v=VS.85).aspx
Thanks
did my solution work for you ??
ASKER
Sorry Shahan, I was testing TommyBoy's post and didn't see yours when I posted my answer. I did try yours though. I got a 57 back, which wasnt documented in the codeproject page. Thanks anyway.
but this post was correct ID: 33130416
>>>> Is there an equivilant to C's errno
the post referring Err.Number was according to your question.
the post referring Err.Number was according to your question.
but any ways you can use both. No problem!
Error Number
Default Error Message
5
Procedure call or argument is not valid
6
Overflow
7
Out of Memory
11
Division by Zero
51
Internal Error
52
Bad file name or number
53
File not found
55
File already open
76
Path not found
482
Printer error
Found from here:
http://www.codeproject.com/KB/dotnet/VB_NET_Error_Handling.aspx