TechTalkz.com Logo

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Programing Languages > C#(C Sharp)

Notices

Reply
 
Thread Tools Display Modes
Old 14-12-2007, 11:20 PM   #1
Sergei Shelukhin
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?
  Reply With Quote
Old 15-12-2007, 12:19 AM   #2
Willy Denoyette [MVP]
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.

  Reply With Quote
Old 15-12-2007, 01:17 AM   #3
Nicholas Paldino [.NET/C# MVP]
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.
>



  Reply With Quote
Old 15-12-2007, 01:18 AM   #4
Willy Denoyette [MVP]
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.
>>

>
>



  Reply With Quote
Reply

Thread Tools
Display Modes




New To Site? Need Help?

All times are GMT +5.5. The time now is 07:37 PM.


vBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2009, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional