Документ взят из кэша поисковой машины. Адрес оригинального документа : http://rtm-cs.sinp.msu.ru/manual/mico/doc/node63.html
Дата изменения: Mon Jun 7 21:54:59 1999
Дата индексирования: Mon Oct 1 21:22:52 2012
Кодировка:
MICO Specific Exception Handling next up previous
Next: No Exception handling Up: Exceptions Previous: CORBA Compliant Exception Handling

MICO Specific Exception Handling

This kind of exception handling has been invented for C++ compilers that do not support catching by base classes. For example it is quite common to catch all system exceptions. Since catching CORBA::SystemException & does not work one would have to write one catch clause for each of the 30 system exceptions. To work around this problem the function mico_throw() and special _var types have been introduced.

You must not use the throw operator directly to throw an exception, instead you should use the function mico_throw() defined in mico/throw.h, which is automatically included by IDL compiler generated code:

  // ok
  mico_throw (CORBA::UNKNOWN());

  // wrong
  throw CORBA::UNKNOWN();

will throw the CORBA system exception UNKNOWN. User defined exceptions are thrown the same way.

Exceptions are always caught by reference using the _var types. System exceptions must be caught by SystemException_var:

  // ok
  try {
    ...
    mico_throw (CORBA::UNKNOWN());
    ...
  } catch (CORBA::SystemException_var &ex) {
    ...
  }

  // wrong
  try {
    ...
    mico_throw (CORBA::UNKNOWN());
    ...
  } catch (CORBA::UNKNOWN_var &ex) {
    ...
  }

  // wrong
  try {
    ...
    mico_throw (CORBA::UNKNOWN());
    ...
  } catch (CORBA::Exception_var &ex) {
    ...
  }

Sometimes it is necessary to know exactly which system exception has been thrown:

  // ok
  try {
    ...
    mico_throw (CORBA::UNKNOWN());
    ...
  } catch (CORBA::SystemException_var &sys_ex) {
    if (CORBA::UNKNOWN *ukn_ex = CORBA::UNKNOWN::_narrow (sys_ex)) {
      // something1
    } else {
      // something2
    }
  }

  // wrong
  try {
    ...
  } catch (CORBA::UNKNOWN_var &ukn_ex) {
    // something1
  } catch (CORBA::SystemException_var &other_ex) {
    // something2
  }

In contrast to system exceptions a user exception X must be caught by X_var (i.e., not by UserException_var):

  // ok
  try {
    ...
    mico_throw (SomeExcept());
    ...
  } catch (SomeExcept_var &some_ex) {
    ...
  }

  // wrong
  try {
    ...
    mico_throw (SomeExcept());
    ...
  } catch (CORBA::UserException_var &usr_ex) {
    ...
  }

  // wrong
  try {
    ...
    mico_throw (SomeExcept());
    ...
  } catch (CORBA::Exception_var &ex) {
    ...
  }

It is possible to write code that works both with CORBA compliant exception handling and MICO specific exception handling. For this one should follow the instructions in this section but replace _var by _catch. In MICO specific exception handling mode X_catch is typedef'ed to X_var, in CORBA compliant exception handling mode X_catch is typedef'ed to X. Furthermore each exception X provides an overloaded -> operator so that you can use -> to access the exception members in the catch body independent of the exception handling mode. Here is an example:

  // throw
  mico_throw (CORBA::UNKNOWN());

  // catch
  try {
    ...
  } catch (CORBA::SystemException_catch &ex) {
    cout << ex->minor() << endl;
  }

If an exception is thrown but not caught MICO will print out a short description of the exception and terminate the process.


next up previous
Next: No Exception handling Up: Exceptions Previous: CORBA Compliant Exception Handling

Arno Puder
Mon Jun 7 10:53:40 PDT 1999