math_FunctionRoot.hxx abort instead of throwing exception

Hi everyone,

I am having trouble with the "math_FunctionRoot" class. It is working fine in mode debug, but it aborts in release mode. I have checked the values in both modes and they are the same, but it aborts when constructing the instance math_FunctionRoot root;

It has a try-catch expression as you can see below:

math_FunctionWithDerivative derivative_func(0,0,0);

try{

   OCC_CATCH_SIGNALS

    math_FunctionRoot root_finder(derivative_func,0,0,0, 100);

}

  catch (StdFail_NotDone &sf)
  {
...
  }
  catch (Standard_Failure &sf)
  {
    ..
  }
  catch (...)

  {

  }

This code works fine in debug mode but in release, the system crashes as it seems opencascade is no throwing any exception. Could tell me please why it is not throwing an exception and why it fails in release mode but not in debug mode?

Thanks ind advance.

Kind regards.

Kirill Gavrilov's picture

This code works fine in debug mode but in release, the system crashes as it seems opencascade is no throwing any exception

What do you mean by "works fine" - that it does not crash or that it produces result / throws exception?
In case if it throws exception - which one (it is better checking this within debugger)?

Note that release build disables (by default) some verbose exceptions for performance reasons - this is expected difference.

Helen Medina's picture

Hi Kirill.

Thank you for your answer.

About your first question, What I mean with "works fine" is that in debug mode the "root_finder" instance (bold line below) is created and it doesn´t throw any exception or crashes. 

math_FunctionRoot root_finder(derivative_func,0,0,0, 100);

root_finder.Root();

... //code continues

However, this same line in release mode just crashes. It does´nt throw any exception.

So, I guess in release build some verbose exceptions are disables as you said. However, still I don´t understand why the root_finder instance is created without any issue. However, in release mode crashes with the same parameters. 

Also, if in release build some exceptions are disabled, so what is the best way to handle this situation as I cannot catch exceptions in release mode?

Thank you for your time. It is very much appreciated.

Kirill Gavrilov's picture

If there is no exception in Debug mode - there is no reason to have it in Release (though the opposite is possible).
Note that as I said - sometime it makes sense to check that there is REALLY no exception within attached debugger,
because exception (in Debug mode) might be handled inside OCCT code, so that you don't see exception within application catch.

Otherwise, I would expect there is a memory corruption somewhere, which exception wouldn't help much - these are difficult to debug.
If stack in Release mode is unclear - try building application (and OCCT) in Release mode with Debug info.

Make sure also initializing redirection of signals (SIGSEGV, SIGFPE, SIGILL) into C++ exceptions using OSD::SetSignal(), which sometime might help to localize issue faster.

Kirill Gavrilov's picture

Note, these are just general tips for debugging - I have not analyzed your code.

Helen Medina's picture

The information is very helpful, I will check it. Thank you very much.

Kind regards