Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I need to clear this warning :

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

The complier is telling me :

The variable 'MyException' is declared but never used

How can I fix this.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
417 views
Welcome To Ask or Share your Answers For Others

1 Answer

  1. You can remove it like this:

    try
    {
        doSomething()
    }
    catch (AmbiguousMatchException)
    {
        doSomethingElse()
    }
    
  2. Use warning disable like this:

    try
    {
        doSomething()
    }
    #pragma warning disable 0168
    catch (AmbiguousMatchException exception)
    #pragma warning restore 0168
    {
        doSomethingElse()
    }
    

Other familiar warning disable

#pragma warning disable 0168 // variable declared but not used.
#pragma warning disable 0219 // variable assigned but not used.
#pragma warning disable 0414 // private field assigned but not used.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...