I thought throwing an exception is good practice to let it bubble back up to the UI or somewhere where you log the exception and notify the user about it.
Why does resharper say it is redundant?
try
{
File.Open("FileNotFound.txt", FileMode.Open);
}
catch
{
throw;
}
Because
is no different than
If the call to
File.Open(string, FileMode)fails, then in either sample the exact same exception will find its way up to the UI.In that
catchclause above, you are simply catching and re-throwing an exception without doing anything else, such as logging, rolling back a transaction, wrapping the exception to add additional information to it, or anything at all.However,
would not contain any redundancies and ReSharper should not complain. Likewise,
would not be redundant.