|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
IO locked errorWhen a user has a file open and of course .NET cant access it due to it
being locked i get an error back like this through an exception System.IO.IOException: The process cannot access the file 'S:\Care.xls' because it is being used by another process. is there any way to trap that specific error and give a user friendly message back? but on any other errors throw an exception? thanks! "Brian Henry" <nospam@nospam.com> schrieb try> When a user has a file open and of course .NET cant access it due to > it being locked i get an error back like this through an exception > > System.IO.IOException: The process cannot access the file > 'S:\Care.xls' because it is being used by another process. > > is there any way to trap that specific error and give a user > friendly message back? but on any other errors throw an exception? > thanks! 'code catch ex as System.IO.IOException 'user friendly message end try Armin That traps all IO errors though... I just want something when the file is
locked to say something like "You already have this file open, please close it and try agian" before you could do this with error codes, with exceptions you dont seem to have them anymore that I know of I still want IO errors like file not found and stuff to throw exceptions outside of the one i already mentioned Brian,
You could examine the exception's Message property. But that runs the risk that the message could change in future versions of the framework. Kerry Moorman Show quoteHide quote "Brian Henry" wrote: > That traps all IO errors though... I just want something when the file is > locked to say something like "You already have this file open, please close > it and try agian" before you could do this with error codes, with exceptions > you dont seem to have them anymore that I know of > > I still want IO errors like file not found and stuff to throw exceptions > outside of the one i already mentioned > > > "Brian Henry" <nospam@nospam.com> schrieb You wrote that you want to catch only IOException, not all other exceptions. > That traps all IO errors though... I just want something when the > file is locked to say something like "You already have this file > open, please close it and try agian" before you could do this with > error codes, with exceptions you dont seem to have them anymore that > I know of > > I still want IO errors like file not found and stuff to throw > exceptions outside of the one i already mentioned That's what the example does. You could rethrow the exception if it's one of the exceptions derived from IOException: (untested) try 'code catch ex as ioexception if ex.gettype is gettype(ioexception) then 'message here else throw end if end try Another way: const ERROR_SHARING_VIOLATION as integer = 32 try 'code Catch ex As IOException When System.Runtime.InteropServices.Marshal.GetLastWin32Error = ERROR_SHARING_VIOLATION 'message end try However, I'm not sure whether error #32 is the only error that indicates a sharing violation. Armin
Referencing "Forms" objects from a module
some advice The old Structure/Class Argument Migrating From ListBox to ListView: Only One Problem DATE HELLLPPPP Command.Close vs Command.Dispose Referencing Datagrid Information Problem on MSHFlexGrid Regarding a dot net application program BindingSource for a class - need a light bulb moment |
|||||||||||||||||||||||