Handling exception when creating a participant
adam-lee opened this issue · 3 comments
It looks like I must use the initializer list to initialize a domain participant:
myReceive::myReceive() : participant_(dds::domain::DomainParticipant(0)) {
// ...
}
If I do something like this:
myReceive:: myReceive() {
participant_ = dds::domain::DomainParticipant(0);
// ...
}
Compiler complains like below:
error: field of type 'dds::domain::DomainParticipant' (aka 'TDomainParticipant<org::eclipse::cyclonedds::domain::DomainParticipantDelegate>') has protected default constructor
The goal is to do try-catch exception handling when dds::domain::DomainParticipant()
fails (ie. when there is no network interfaces). How can I do something like this? Ty!
I don't know the rules of C++ exceptions so well, but maybe @e-hndrks (who knows the DDS C++ API well) knows the answer straightaway 🙂
Hi @adam-lee,
I think the compilation error here is not about the assignment of your participant, but about the declaration of the participant variable that is going to hold your future participant. You probably declared the participant_ variable like this:
dds::domain::Participant participant_;
With this statement you instruct the compiler to create a participant, without telling it what domainId to use for this participant. Since every participant needs a mandatory domainId, the default (empty) constructor was set to private causing your compilation error.
However, the dds spec does allow you to create an empty participant variable that you intend to assign later, but you will have to do it like this:
dds::domain::Participant participant_(dds::core::null)
The rest of your code should then just work like you intended. So I hope this works for you.
Regards,
Erik Hendriks.