473,386 Members | 1,602 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

identify IOException?

Hi. I catch IOException and want to separate the case when I receive
"The process cannot access the file because it is being used by
another process" error from other possible IOException-s. Checking the
message text is not an option because the app is multilingual and
might use a .NET version that is not English.

Is there any way to do it, some error code or something?
Dec 14 '07 #1
3 1825
"Sergei Shelukhin" <re******@gmail.comwrote in message
news:4c**********************************@t1g2000p ra.googlegroups.com...
Hi. I catch IOException and want to separate the case when I receive
"The process cannot access the file because it is being used by
another process" error from other possible IOException-s. Checking the
message text is not an option because the app is multilingual and
might use a .NET version that is not English.

Is there any way to do it, some error code or something?

Call Marshal.GetLastWin32Error in your catch handler, and check the Win32
error code.

Willy.

Dec 14 '07 #2
That's depending a little bit too much on an implementation detail, IMO.
Granted, file access is probably ALWAYS going to be done through the
P/Invoke layer, but the assumption that there will be no calls to the
P/Invoke layer between the throwing of the exception and the next call to
GetLastWin32Error is a brittle suggestion, at best.

What the OP should really do is make the call to CreateFile himself, and
interpret the error code (if there is one).

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:uB**************@TK2MSFTNGP04.phx.gbl...
"Sergei Shelukhin" <re******@gmail.comwrote in message
news:4c**********************************@t1g2000p ra.googlegroups.com...
>Hi. I catch IOException and want to separate the case when I receive
"The process cannot access the file because it is being used by
another process" error from other possible IOException-s. Checking the
message text is not an option because the app is multilingual and
might use a .NET version that is not English.

Is there any way to do it, some error code or something?


Call Marshal.GetLastWin32Error in your catch handler, and check the Win32
error code.

Willy.

Dec 14 '07 #3
If this is your concern just call Marshal.GetHRForException which returns
the HResult associated with the Exception thrown, mask the highest 16 bits
off and you have the Win32 error code.

Willy.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:uu**************@TK2MSFTNGP06.phx.gbl...
That's depending a little bit too much on an implementation detail,
IMO. Granted, file access is probably ALWAYS going to be done through the
P/Invoke layer, but the assumption that there will be no calls to the
P/Invoke layer between the throwing of the exception and the next call to
GetLastWin32Error is a brittle suggestion, at best.

What the OP should really do is make the call to CreateFile himself,
and interpret the error code (if there is one).

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:uB**************@TK2MSFTNGP04.phx.gbl...
>"Sergei Shelukhin" <re******@gmail.comwrote in message
news:4c**********************************@t1g2000 pra.googlegroups.com...
>>Hi. I catch IOException and want to separate the case when I receive
"The process cannot access the file because it is being used by
another process" error from other possible IOException-s. Checking the
message text is not an option because the app is multilingual and
might use a .NET version that is not English.

Is there any way to do it, some error code or something?


Call Marshal.GetLastWin32Error in your catch handler, and check the Win32
error code.

Willy.


Dec 14 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: borny | last post by:
Hi everyone, we' are using Websphere Application Server (WAS) 3.02 and Websphere Commerce Suite (WCS) 4.01 (on AIX platform) for our application. Now and then we get an IOexception with following...
19
by: Sharon | last post by:
Hi, When I'm doing BinaryFormatter.Deserialize() over a TCP socket. When I'm closing the TcpListener by invoking the TcpListener.Stop(); I get: System.IO.IOException with message "Unable to...
2
by: Krissy | last post by:
Hi all, Yesterday we upgraded our server to the 1.1 Framework. (from 1.0) Our project was also converted in Visual Studio to 1.1 Since we have uploaded the project, we are getting an error...
6
by: Chad Crowder | last post by:
Getting the following error on my production server whether the file exists or not: "System.IO.IOException: Cannot create a file when that file already exists." Here's the code generating the...
0
by: Carl Rapson | last post by:
I have some code that is checking a directory for subdirectories, using the Directory.GetDirectories method (I got this code from a sample app): Dim directories as String() Try directories =...
0
by: Aryeh Holzer | last post by:
Hi, I've been trying to use the weather webservice available from the National Weather Service (NWS), at http://www.nws.noaa.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML. wsdl without success. Here's...
6
by: Pieter | last post by:
Hi, For some procedures that throws exceptions, I would like to show different messages to the user depending on what type of exception he's getting. For instance this one: when the file is...
6
by: Zytan | last post by:
I got a System.IO.IOException in my app on another computer, so I couldn't debug it. I don't think it was a HD error. What else could throw this? Could it be from reading a webpage from the...
1
by: Rymfax | last post by:
I've created a Download Manager application and I'm having a problem with some clients where for whatever reason, the remote connection is forceably closed (whether on the client side or server...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.