The variable 'MyException' is declared but never used

前端 未结 6 1991
迷失自我
迷失自我 2020-12-05 09:36

I need to clear this warning :

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

The complier

6条回答
  •  悲&欢浪女
    2020-12-05 09:46

    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.
    

提交回复
热议问题