Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

396
Views
Disabled first-chance-exception but debugger stopps within try...catch when using IronPython

The following code should be executed without stopping the debugger:

var engine = Python.CreateEngine(AppDomain.CurrentDomain);
var source = engine.CreateScriptSourceFromString("Foo.Do()");
var compiledCode = source.Compile(new PythonCompilerOptions { Optimized = true });

try
{
    compiledCode.Execute(
         engine.CreateScope(
            new Dictionary<string, object> { 
                                            { "Foo", new Foo() }
                                           }));

    MessageBox.Show("Executed without error");
}
catch (Exception ex)
{
    MessageBox.Show(string.Format("Error at execution: {0}", ex.Message));
}

Using this class:

public class Foo
{
    public void Do()
    {
        throw new InvalidOperationException("The debugger should not break here...");
    }
}

The script execution runs in a try-block to handle any exception. If I have code like 1 / 0 all works perfekt. The exception is created in Python (or in the engine) and my catch-block is called as expected without forcing the debugger to stop anywhere.

Calling try { new Foo().Do(); } catch {} in C# does also work without stopping the debugger.

But throwing an exception in C#-code that's invoked in python will force the debugger to stop at the throw new...-line.

I don't want the debugger to stop there.

I disabled the first-chance-exceptions in Debug/Exceptions but the debugger still stops at throw.

I can't use DebuggerStepThrough because in my working code the exception it not thrown in this method but deeper in the code. The code is also used out of C# and decorating all these methods with DebuggerStepThrough will make my C# debugger obsolete.

A solution is to disable User-unhandled exceptions in Debug/Exceptions too but I want to break at exceptions that aren't handled by the user so this is not an option.

What can I do to disable the first-chance-exception called out of python code that's executed in a try...catch block?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Most likely, you have a default option checked in your Debugging settings that's causing this:

enter image description here

Make sure that box is unchecked and you should be good to go. Hopefully that helps!

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!