Alex Rivera | Logout

C# value is declared but never used

Asked 2009-12-11T11:45:11.350
9

I have a try and catch where I am catching different error types:

catch (XmlException XmlExp)
{
    return false; 
}

catch (XmlSchemaException XmlSchExp)
{
    return false; 
}
catch (Exception GenExp)
{
    throw GenExp;
}

Notice that XMLException XMLExp is declared but never used. Is it possible to catch the XMLException without declaring a local variable?

Is this valid code:

catch (XmlException)
{
    return false; 
}
c#
Edit
Report

1 Answer

6

Do this

catch (XmlException)
{
   return false; 
}

catch (XmlSchemaException)
{
   return false; 
}

catch (Exception)
{
   throw;
}
answered 2009-12-11T12:11:45.787

Your Answer