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.
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.
The trouble is, you aren't using your variable
MyException
anywhere. It gets declared, but isn't used. This isn't a problem... just the compiler giving you a hint in case you intended to use it.You can simply write:
and omit the exception name if you won't be using it in the catch clause.
but never used
means that you should use it after catch() such as writing its value to console, then this warning message will disappear.You can remove it like this:
Use warning disable like this:
Other familiar warning disable
You declare a name for the exception, MyException, but you never do anything with it. Since it's not used, the compiler points it out.
You can simply remove the name.
You could write the exception out to a log if you've got one running. Might be useful for tracking down any problems.