Suppress warning on unused exception variable in C#
Define the catch clause without the exception variable as follows:
try {
someMethod();
} catch (XYZException) {
// do something without using e
}
Define the catch clause without the exception variable as follows:
try {
someMethod();
} catch (XYZException) {
// do not state e in catch clause
}
Another option is to use
try
{
someMethod();
}
#pragma warning disable 0168
catch (XYZException e)
#pragma warning restore 0168
{
// do not state e in catch clause
}
This is useful in visual studio 2015 because it doesn't have a way to see the exception by default when debugging with a breakpoint on the catch.