变量 'MyException' 已声明但从未在实例中使用
The variable 'MyException' is declared but never used in the instance
我需要清除这个警告:
try
{
// doSomething();
}
catch (AmbiguousMatchException MyException)
{
// doSomethingElse();
}
编译器告诉我:变量 'My Exception' 已声明但从未使用过
我该如何解决这个问题。
如果你不打算使用异常细节,你可以像这样使用:
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();
}
否则您必须将变量用于以下内容:
try
{
doSomething();
}
catch (AmbiguousMatchException MyException)
{
WriteToLog(MyException.ToString());
// doSomethingElse();
}
其中 WriteToLog
方法将定义如下:
public static void WriteToLog(string exceptionDetails) {
// write the details to a file/DB
}
试试这个,
try
{
doSomething()
}
catch (AmbiguousMatchException)
{
doSomethingElse()
}
我需要清除这个警告:
try
{
// doSomething();
}
catch (AmbiguousMatchException MyException)
{
// doSomethingElse();
}
编译器告诉我:变量 'My Exception' 已声明但从未使用过
我该如何解决这个问题。
如果你不打算使用异常细节,你可以像这样使用:
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();
}
否则您必须将变量用于以下内容:
try
{
doSomething();
}
catch (AmbiguousMatchException MyException)
{
WriteToLog(MyException.ToString());
// doSomethingElse();
}
其中 WriteToLog
方法将定义如下:
public static void WriteToLog(string exceptionDetails) {
// write the details to a file/DB
}
试试这个,
try
{
doSomething()
}
catch (AmbiguousMatchException)
{
doSomethingElse()
}