RETCODE_OK no longer in java?

4 posts / 0 new
Last post
Last seen: 4 years 3 months ago
Joined: 05/21/2014
Posts: 46
RETCODE_OK no longer in java?

I am unable to use the RETCODE_OK  in java. All the other RETCODE_ work. Is there something that has changed in the API or has this been removed from the java version?

Last seen: 3 years 3 months ago
Joined: 01/15/2013
Posts: 94


How are you using it? I assume you're using version 5.1.0 and you were using 5.0.0?

Recall that in Java, return codes are exceptions. RETCODE_ERROR is the base class of all other exceptions. I think you shouldn't need to check return values, but try-catch these exceptions.

Does this make sense to you? How were you using RETCODES before?



Last seen: 4 years 3 months ago
Joined: 05/21/2014
Posts: 46

Yes that does. I was trying to use a C++/C example that had no java conversion written and write the example in java. That is where my confusion was coming in. What would then be the right thing to use in place of RETCODE_OK in the code below?

/* set up the waitset: */
DDSWaitSet* waitset = new DDSWaitSet();
DDSStatusCondition* cond = writer->get_statuscondition();
DDS_ReturnCode_t retcode;
retcode = waitset->attach_condition(cond);
if (retcode != DDS_RETCODE_OK) {
    // ... error
/* use the waitset to wait for the condition to become true */
DDS_Duration_t timeout = { 1, 0 }; // 1 second
DDS_ConditionSeq active_conditions;
do {
    retcode = waitset->wait(active_conditions, timeout);
} while(retcode == DDS_RETCODE_TIMEOUT);
if (retcode != DDS_RETCODE_OK) {
    // ... error
/* active_conditions should include a single entry which matches cond */
/* ... */
/* clean up */
delete waitset;


Fernando Garcia's picture
Last seen: 6 months 3 weeks ago
Joined: 05/18/2011
Posts: 199

Hi jgr208, 

We have recently translated that example to Java. You can download from example either from the examples section or browse it from our Github repository. This would be a quick translation of the code you posted to Java:

            StatusCondition status_condition = reader.get_statuscondition();
            if (status_condition == null) {
                System.err.println("get_statuscondition error\n");


            WaitSet waitset = new WaitSet();
            ConditionSeq active_conditions_seq = 
                    new ConditionSeq();
            Duration_t wait_timeout = new Duration_t();
            wait_timeout.sec = 1;
            wait_timeout.nanosec = 500000000;

            bool exit = false;
            do { 
                try {
                    waitset.wait(active_conditions_seq, wait_timeout);
                } catch (RETCODE_TIMEOUT e) {
                          "Wait timed out!! No conditions were triggered.\n");
                    exit = true;
            }  while(!exit);