Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

405
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda