question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

VB -> C#: OnErrorGoToStatementSyntax and OnErrorResumeNextStatementSyntax

See original GitHub issue
  • OnErrorGoToStatementSyntax, OnErrorResumeNextStatementSyntax
    • Many cases can probably be reasonably successfully converted as try...catch and then a goto within the catch and an appropriately placed label

Resume Next Example

    int lineNumber = 1;
    try
    {
        line1: lineNumber++;
        //First line of code would be here
        line2: lineNumber++;
        //Second line of code would be here    
    }
    catch
    {
        switch(lineNumber)
        {
            case 1: goto line1;
            case 2: goto line2;
        }
    }

Note: Even this messy solution isn’t valid because line1 is out of scope of the catch block and could be in a nested scope even within the try block

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
valeriu33commented, Mar 5, 2020

I found this issue as well, my project has a lot of "On Error GoTo"s and I’d be grateful if someone implemented this syntax image

0reactions
GrahamTheCodercommented, Aug 10, 2023

One idea for implementing exactly the resume next logic:

static void Main(string[] args)
    {
        Wrap(() =>
        {
            Console.WriteLine("First line");
        });

       int result = default;
        Wrap(() =>
        {
            result = Divide(10, 0); // Division by zero to simulate an error not directly in the method at hand that therefore shouldn't be supressed
        });

        Wrap(() =>
        {
            Console.WriteLine("Third line " + result);
        });
    }

    // Not sure if line number will help, but something like this to be able to match the stack trace's top frame
    static void Wrap(Action action, [CallerLineNumber] int lineNumber = 0)
    {
        try
        {
            action.Invoke();
        }
        catch (Exception ex)
        {
            if (IsDirectlyWithinLambda(ex, lineNumber))
            {
                // Handle or suppress the exception
                Console.WriteLine($"Exception suppressed at line {lineNumber}: {ex.Message}");
            }
            else
            {
                throw; // Rethrow if not directly within the lambda
            }
        }
    }
}

Read more comments on GitHub >

github_iconTop Results From Across the Web

VisualBasicSyntaxWalker Class
Represents a VisualBasicSyntaxVisitor that descends an entire SyntaxNode tree visiting each SyntaxNode and its child SyntaxNodes and SyntaxTokens in ...
Read more >
SyntaxKind.vb
''' Represents an OnError Resume Next statement. ''' </summary>; OnErrorResumeNextStatement = 199 ' OnErrorResumeNextStatementSyntax ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found