Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / CORBA / January 2007

Tip: Looking for answers? Try searching our database.

checking for org.omg.CORBA.OBJECT_NOT_EXIST

Thread view: 
donalmurtagh@yahoo.co.uk - 22 Jan 2007 15:38 GMT
Hi,

I'm writing a java CORBA client, using the Visibroker ORB. Sometimes
when I call methods on the remote object references I get the following
exception

org.omg.CORBA.OBJECT_NOT_EXIST:   vmcid: OMG  minor code: 0  completed:
No

Is there some way that I can check beforehand whether this exception
will be thrown, i.e. whether the remote object still exists? I thought
that I could do it like this:

   if (myRef._non_existent()) {

       // get a new myRef
   }

   myRef.doRemoteMethod();

But I've found that _non_existent() throws exceptions. Is there a
better way to check for the state that causes an OBJECT_NOT_EXIST
exception?

Regards,
Dan
ke_jin@yahoo.com - 23 Jan 2007 17:05 GMT
> Hi,
>
[quoted text clipped - 19 lines]
> better way to check for the state that causes an OBJECT_NOT_EXIST
> exception?

We should say thanks to OMG that made this change in 2.3 (or earlier?).
Now, your best around is to be write a wrapper that catches exceptions
and return true.

For visibroker, I recall it has a property you can set that will force
the ORB to be backward compatible to CORBA 2.2, namely, non_existent()
returns true, instead of throwing a exception, when it fails to connect
to the server.

Regards,
Ke

> Regards,
> Dan
Jonathan Biggar - 23 Jan 2007 18:35 GMT
> We should say thanks to OMG that made this change in 2.3 (or earlier?).
> Now, your best around is to be write a wrapper that catches exceptions
[quoted text clipped - 4 lines]
> returns true, instead of throwing a exception, when it fails to connect
> to the server.

I consider that broken behavior, which is why the standard was clarified
in 2.3 to allow non_existent() to throw exceptions.

non_existent() returning true when it can't contact the server is likely
returning a lie.

Just write your own wrapper function that calls non_existent(), catches
the exceptions you want, and returns different error codes for different
exceptions.  Once you've done that, you can reuse that code everywhere
without having to write lots of catch() blocks.

Signature

Jon Biggar
Floorboard Software
jon@floorboard.com
jon@biggar.org

ke_jin@yahoo.com - 24 Jan 2007 18:23 GMT
> Just write your own wrapper function that calls non_existent(), catches
> the exceptions you want, and returns different error codes for different
> exceptions.  Once you've done that, you can reuse that code everywhere
> without having to write lots of catch() blocks.

Then, you would end up with exactly same "lots of" switch/case blocks
:).

Regards,
Ke

> --
> Jon Biggar
> Floorboard Software
> jon@floorboard.com
> jon@biggar.org
Jonathan Biggar - 24 Jan 2007 18:28 GMT
>> Just write your own wrapper function that calls non_existent(), catches
>> the exceptions you want, and returns different error codes for different
[quoted text clipped - 3 lines]
> Then, you would end up with exactly same "lots of" switch/case blocks
> :).

Not if you design the error codes right, or make predicate functions
that you can reuse that translate the error code to a boolean value.

Signature

Jon Biggar
Floorboard Software
jon@floorboard.com
jon@biggar.org

ke_jin@yahoo.com - 24 Jan 2007 19:15 GMT
> >> Just write your own wrapper function that calls non_existent(), catches
> >> the exceptions you want, and returns different error codes for different
[quoted text clipped - 6 lines]
> Not if you design the error codes right, or make predicate functions
> that you can reuse that translate the error code to a boolean value.

As long as your wrapper "returns different error codes for different
exceptions".

Here is an example:

original code with many try/catch:

   try {
      ....
  }
  catch(exception a) {
     handle_exception_a(...);
  }
  catch(exception b) {
     handle_exception_b(...);
  }
  ...

wrapper that "returns different error codes for different exceptions":
...

int wrapper() {
  ...
  try {
      ....
  }
  catch(exception a) {
     return error_code_a;
  }
  catch(exception b) {
     return error_code_b;
  }
  ...
}

Use of this wrapper:

  ...
  switch(wrapper()) {
     case error_code_a: handle error a; break;
     case error_code_b: handle error b; break;
    ...
  }

Regards,
Ke

> --
> Jon Biggar
> Floorboard Software
> jon@floorboard.com
> jon@biggar.org
Jonathan Biggar - 25 Jan 2007 18:48 GMT
>>>> Just write your own wrapper function that calls non_existent(), catches
>>>> the exceptions you want, and returns different error codes for different
[quoted text clipped - 7 lines]
> As long as your wrapper "returns different error codes for different
> exceptions".

You're missing my point.

> Here is an example:
>
[quoted text clipped - 36 lines]
>      ...
>    }

Or:

bool error_codes_i_care_about(error code e) {
    switch (e) {
    case error_code_a:
    case error_code_c:
        return true;
    default:
        return false;
    }
}

error_code wrapper(CORBA::Object_ptr obj) {
    try {
        ....
    }
    catch(exception a) {
        return error_code_a;
    }
    catch(exception b) {
        return error_code_b;
    }
    ...
}

bool wrapper(CORBA::Object_ptr obj, bool (*predicate)(errror_code)) {
    return predicate(wrapper(obj));
}

    ...
    if (wrapper(obj, error_codes_i_care_about)) {
        // handle errors I care about
    else
        // do something else
    ...

Signature

Jon Biggar
Floorboard Software
jon@floorboard.com
jon@biggar.org



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.