Skip to main content

Catch block is empty

In This Article

CodeRush Classic shows the Catch block is empty code issue if a catch block contains nothing.

#Fix

Add the needed code to the empty catch block.

#Purpose

Catch block is empty directs your attention to empty catch blocks, because they usually denote an incomplete code.

#Example

private string _Data;
public void SaveData(string path)
{
    try
    {
        File.WriteAllText(path, _Data);
    }
    catch (Exception ex)
    {

    }
}

Fix:

private string _Data;
public void SaveData(string path)
{
    try
    {
        File.WriteAllText(path, _Data);
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
    }
}