Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid breaking on generated code

I am using some external code which when called with certain parameters throws an exception which can be ignored. Unfortunately I can not change this external code for various reasons.

I have created a wrapper method which looks something like this:

    [DebuggerStepThrough]
    public static bool TryGetXXX(string input, out string output)
    {
        try
        {
            output = MethodThatSometimesFails(input);
            return true;
        }
        catch
        {
            output = null;
            return false;
        }
    }

    private static string MethodThatSometimesFails(string input)
    {
        // Don't want this to cause a break
        // but can not put the attribute on this method
        throw new Exception("couldnt deal with your request");
    }

Unfortunately though, the external code will still break at the exception inside MethodThatSometimesFails. The [DebuggerStepThrough] will only avoid debugging the code above, but the called code will still throw.

What I would like is that the code just runs even with all of check boxes on the "Exceptions..." window checked. Is there an attribute which can do this?

If there is no attribute I could create a project containing these classes / methods and exclude the entire project. Is there a way to do this?

like image 892
Blueberry Avatar asked May 17 '26 03:05

Blueberry


1 Answers

Try mark method or class with DebuggerNonUserCodeAttribute

like image 87
STO Avatar answered May 18 '26 15:05

STO