Usung C++11 API with no exceptions

3 posts / 0 new
Last post
ilya_1725's picture
Offline
Last seen: 2 years 5 months ago
Joined: 04/20/2020
Posts: 24
Usung C++11 API with no exceptions

We've used the RTI traditional C++ API before with linked libraries. Now we would like to use the "modern" C++11 API.

However, our applications are compiled with exceptions disabled (-fno-exceptions). This cases the compilation to fail:

 

In file included from /home/user/rti_connext_dds-6.0.1/include/ndds/hpp/rti/core/LocatorFilter.hpp:27,
                 from /home/user/rti_connext_dds-6.0.1/include/ndds/hpp/rti/core/policy/CorePolicy.hpp:40,
                 from /home/user/rti_connext_dds-6.0.1/include/ndds/hpp/dds/core/policy/detail/CorePolicy.hpp:26,
                 from /home/user/rti_connext_dds-6.0.1/include/ndds/hpp/dds/core/policy/CorePolicy.hpp:27,
                 from /home/user/rti_connext_dds-6.0.1/include/ndds/hpp/rti/domain/qos/DomainParticipantQosImpl.hpp:26,
                 from /home/user/rti_connext_dds-6.0.1/include/ndds/hpp/dds/domain/qos/detail/DomainParticipantQos.hpp:27,
                 from /home/user/rti_connext_dds-6.0.1/include/ndds/hpp/dds/domain/qos/DomainParticipantQos.hpp:26,
                 from /home/user/rti_connext_dds-6.0.1/include/ndds/hpp/dds/domain/TDomainParticipant.hpp:32,
                 from /home/user/rti_connext_dds-6.0.1/include/ndds/hpp/dds/domain/detail/DomainParticipant.hpp:26,
                 from /home/user/rti_connext_dds-6.0.1/include/ndds/hpp/dds/domain/DomainParticipant.hpp:26,
                 from /home/user/archer/build/_deps/idl-build/idl/idl/version.hpp:24,
                 from /home/user/archer/avionics_apps/apps/test_application/src/test_application.cpp:14:
/home/user/rti_connext_dds-6.0.1/include/ndds/hpp/rti/core/Locator.hpp: In member function ‘rti::core::Locator& rti::core::Locator::address(const ByteSeq&)’:
/home/user/rti_connext_dds-6.0.1/include/ndds/hpp/rti/core/Locator.hpp:230:69: error: exception handling disabled, use ‘-fexceptions’ to enable
  230 |             throw dds::core::InvalidArgumentError("address too long");
      |                                                                     ^

 

  • Is it even possible to use modern C++11 API with no exceptions?
  • If it is, is there examples and documentation of that?

 

Thank you,

-Ilya.

Keywords:
Offline
Last seen: 1 month 3 weeks ago
Joined: 04/02/2013
Posts: 196

Hi Ilya,

It's not possible.

The way the API is designed only makes sense when errors are reported through exceptions. Otherwise we wouldn't be able to extensively use constructors, assignment and move operators, value-type semantics, etc.

One of the reasons we still maintain the traditional C++ API is for use cases where exceptions are not allowed. 

Alex

ilya_1725's picture
Offline
Last seen: 2 years 5 months ago
Joined: 04/20/2020
Posts: 24

Hi Alex:

 

I understand. It is a bit sad though.

Which C++ API can I use with no exceptions?

What about rtiddsgen tool? I've used it with `-language c++` parameter and it generated code with expections.

For example, this is the code generated with `-language c++`

 

    try {

        if (dst == NULL || src == NULL) {
            return RTI_FALSE;
        }

        if (!RTICdrType_copyChar (
            &dst->major, &src->major)) { 
            return RTI_FALSE;
        }
        return RTI_TRUE;

    } catch (const std::bad_alloc&) {
        return RTI_FALSE;
    }

 

The same code with `-language C` looks this:

    if (dst == NULL || src == NULL) {
        return RTI_FALSE;
    }

    if (!RTICdrType_copyChar (
        &dst->major, &src->major)) { 
        return RTI_FALSE;
    }

 

No exceptions even though it is calling the same underlined function RTICdrType_copyChar.

 

Thank you,

-Ilya.