Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

catching a certain error 1

Status
Not open for further replies.

bouwob

Programmer
Apr 12, 2006
171
0
0
US
I am tryiing to copy files in my program and am having trouble with the program not updating the db correctly the file already exists. I have a try catch but need to catch a system.io.ioexception .... already exists and do one thing with it but something else for everything else.

any ideas
 
Can't you:

try
{
}
catch(Exception ex)
{
switch(ex.GetType().ToString())
{
case "System.Io.IOException":
{
//do something
}
default:
{
//do something else
}
}
}
 
Isn't the proper way supposed to be:

Code:
try
{
}
catch (System.IOException ioex)
{
   Do Something;
}
catch (System.Exception ex)
{
   Do Something else;
}

or have I completely missed something?
 
How about using File.Exists to see if it exists before you try to copy? It seems to me that this would be a more efficient way of handling it....

-Dell

A computer only does what you actually told it to do - not what you thought you told it to do.
 
try
{
}
catch (System.IOException ioex)
{
Do Something;
}
catch (System.Exception ex)
{
Do Something else;
}

Hmmm - good point! And Dell has the proactive approach!
 
I get this message though

Error 5 The type or namespace name 'IOException' does not exist in the namespace 'System' (are you missing an assembly reference?) C:\Worker.cs 205 51 WindowsApplication1

How can I fix this?
 
Check your spelling - it should be "IOException"

If you're still getting this error, this means that the IDE or compiler is not able to locate the System namespace, and that's a problem. Try creating a new solution/project to see if it works for that one.

If not, you'll need to remove/re-add your reference to the System assembly. Go to your references, right-click, and remove. Right-click again, and add it back.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
It should be

catch (System.IO.IOException ioex)

----------------------------------------

TWljcm8kb2Z0J3MgIzEgRmFuIQ==
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top