Restore Error Handling Quick Fix

Introduces an error-handling subroutine to ensure error state is properly handled on scope exit.

This quick-fix is available for the UnhandledOnErrorResumeNext inspection

Applicability

This quick-fix can be applied as a single operation at the following scopes:
  • Procedure
  • Module
  • Project

Examples

 This example depicts the state of module(s) before and after applying the quick-fix.

Before
Module1 (Any)
Option Explicit Public Sub DoSomething() On Error Resume Next Debug.Print ActiveWorkbook.FullName End Sub
After
Module1 (Any)
Option Explicit Public Sub DoSomething() On Error GoTo ErrHandler Debug.Print ActiveWorkbook.FullName Exit Sub ErrHandler: If Err.Number > 0 Then 'TODO: handle specific error Err.Clear Resume Next End If End Sub

Rubberduck.CodeAnalysis.QuickFixes.Concrete.RestoreErrorHandlingQuickFix.cs (Prerelease-v2.5.2.6174)