How to handle a try and catch to handle Standard_Failure?

How to handle a try and catch to handle Standard_Failure?

    try  
    {
       //some OCC code...
    }
    catch (Standard_Failure) 
    {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        PyErr_SetString(PartExceptionOCCError, e->GetMessageString());
    }

It seems that Standard_Failure::Caught(); does not longer exist?

should we use: catch (Standard_Failure& err)

or use : catch(Handle(Standard_Failure) err)

Kirill Gavrilov's picture
  try
  {
    OCC_CATCH_SIGNALS
    // do OCCT stuff
  }
  catch (const Standard_Failure& theErr)
  {
    Message::SendFail() << "OCCT exception caught:\n" << theErr;
  }

or in paranoid verbose mode:

  try
  {
    // OCC_CATCH_SIGNALS is required on Linux platforms
    // to catch signals (access violation and similar), activated by OSD::SetSignal()
    OCC_CATCH_SIGNALS

    // do OCCT stuff
  }
  catch (const Standard_Failure& theFailure)
  {
    TCollection_AsciiString anErr = TCollection_AsciiString ("OCCT exception caught:\n")
                                  + theFailure.GetMessageString() + " [" + theFailure.DynamicType()->Name() + "]";
    Message::SendFail (anErr);
    if (*theFailure.GetStackString() != '\0')
    {
      // print backtrace, managed by OSD::SetSignalStackTraceLength()
      // and Standard_Failure::SetDefaultStackTraceLength()
      Message::SendTrace (theFailure.GetStackString());
    }
  }
  catch (const std::exception& theStdException)
  {
    TCollection_AsciiString anErr = TCollection_AsciiString ("STL exception caught:\n")
                                  + theStdException.what() + " [" + typeid(theStdException).name() + "]";
    Message::SendFail (anErr);
  }
  catch (...)
  {
    TCollection_AsciiString anErr = "Unknown exception caught";
    Message::SendFail (anErr);
  }
Guido van Hilst not specified's picture

Thanks!

liaodi di's picture

i have a function as follows:
bool func( ... ){
try {
OCC_CATCH_SIGNALS
//do something
}
catch ( const Standard_Failure& theFailure){
}
catch ( const std::exception& theExcetp){
}
catch( ... ){
}
...
}
it doesnt work with OCC_CATCH_SIGNALS when i call this function the process crashed directly ,i am really confused.
i tried with OCC_CATCH_SIGNALS,it works sometimes ,but not always.
Is there any rule when we use try/catch to handle OCC related exception?
i use { } to include the code when try/catch exception.