#XXX | Add exception logging to static methods that swallow exceptions

Resolved 💬 3 comments Opened Dec 7, 2025 by drdzey Closed Feb 8, 2026

Problem

95% of the codebase uses static methods that catch exceptions and either:

  1. Show a MessageBox dialog to the user
  2. Silently swallow the exception (empty catch blocks)

This makes debugging extremely difficult because:

  • Errors are not logged anywhere
  • Stack traces are lost
  • Issues are hard to reproduce and diagnose

Current Pattern (Bad)

public static void SomeMethod()
{
    try
    {
        // ... code ...
    }
    catch (COMException comException)
    {
        // Silently swallowed!
    }
    catch (Exception exception)
    {
        MessageBoxHelper.ShowErrorMessage(exception.Message);
        // Stack trace lost, not logged
    }
}

Proposed Solution

Add logging to ALL catch blocks:

public static void SomeMethod()
{
    try
    {
        // ... code ...
    }
    catch (COMException comException)
    {
        Logger.LogWarning(comException, "COM exception in SomeMethod");
    }
    catch (Exception exception)
    {
        Logger.LogError(exception, "Error in SomeMethod");
        MessageBoxHelper.ShowErrorMessage(exception.Message);
    }
}

Scope

Files/areas to update:

  • [ ] CommonFiles/Helpers/**/*.cs - Helper classes
  • [ ] CommonFiles/WPF.UserControls/**/*.cs - User controls
  • [ ] CopyPaste/**/*.cs - CopyPaste add-in
  • [ ] ExcelFormulas/**/*.cs - Excel formulas add-in
  • [ ] AppraisalData/Helpers/**/*.cs - Data helpers
  • [ ] SVITasksApp/**/*.cs - Panel app

Implementation Notes

  1. For static methods, use ISharedLoggerFactory resolved from DI:

``csharp
private static readonly Lazy<ILogger> _logger = new(() =>
FutureDependencyInjector.Resolve<ISharedLoggerFactory>().GetLogger(typeof(ClassName)));
``

  1. Or consider refactoring static methods to instance methods where feasible
  1. Log levels:
  • LogError - For exceptions that affect functionality
  • LogWarning - For COMExceptions and recoverable errors
  • LogDebug - For expected/handled scenarios

Acceptance Criteria

  • [ ] All empty catch blocks have logging added
  • [ ] All catch blocks that show MessageBox also log the full exception
  • [ ] Stack traces are preserved in logs
  • [ ] Logs include method name/context for easier debugging

🤖 Generated with Claude Code

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗