0

I need to clear this warning :

try
 {
    // doSomething();
 }
 catch (AmbiguousMatchException MyException)
 {
    // doSomethingElse();
 }

The compiler is telling me : The variable 'My Exception' is declared but never used

How can I fix this.

sujith karivelil
  • 28,671
  • 6
  • 55
  • 88

2 Answers2

3

Try this one,

try
{
    doSomething()
}
catch (AmbiguousMatchException)
{
    doSomethingElse()
}
Rob
  • 26,989
  • 16
  • 82
  • 98
Prabhat Sinha
  • 1,500
  • 20
  • 32
2

If you are not going to use the exception details, you can use the try like this:

try
{
    doSomething();
}
catch // all types of exceptions will caught here
// if you need to deal with particular type of exceptions then specify them like
//  catch (AmbiguousMatchException)
{
    doSomethingElse();
}

Or else you have to use the variable for something like the following:

try
{
    doSomething();
}
catch (AmbiguousMatchException MyException)
{
    WriteToLog(MyException.ToString());
  //  doSomethingElse();
}

where WriteToLog method will be defined as like the following:

public static void WriteToLog(string exceptionDetails) { 
  // write the details to a file/DB
}
sujith karivelil
  • 28,671
  • 6
  • 55
  • 88