![]() |
|
|
#1 |
|
Guest
Posts: n/a
|
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? |
|
|
|
#2 |
|
Guest
Posts: n/a
|
Re: identify IOException?
"Sergei Shelukhin" <realgeek@gmail.com> wrote in message
news:4ccaed23-4b81-4fe6-9bb2-646a5b5fe718@t1g2000pra.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. |
|
|
|
#3 |
|
Guest
Posts: n/a
|
Re: identify IOException?
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] - mvp@spam.guard.caspershouse.com "Willy Denoyette [MVP]" <willy.denoyette@telenet.be> wrote in message news:uB5e3EoPIHA.1188@TK2MSFTNGP04.phx.gbl... > "Sergei Shelukhin" <realgeek@gmail.com> wrote in message > news:4ccaed23-4b81-4fe6-9bb2-646a5b5fe718@t1g2000pra.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. > |
|
|
|
#4 |
|
Guest
Posts: n/a
|
Re: identify IOException?
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]" <mvp@spam.guard.caspershouse.com> wrote in message news:uuc8cNoPIHA.3676@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] > - mvp@spam.guard.caspershouse.com > > "Willy Denoyette [MVP]" <willy.denoyette@telenet.be> wrote in message > news:uB5e3EoPIHA.1188@TK2MSFTNGP04.phx.gbl... >> "Sergei Shelukhin" <realgeek@gmail.com> wrote in message >> news:4ccaed23-4b81-4fe6-9bb2-646a5b5fe718@t1g2000pra.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. >> > > |
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
| New To Site? | Need Help? |