Netscape Internet Service Broker for C++ Programmer's Guide

[Previous] [Contents]

Appendix A
Platforms without C++ Exception Support

This appendix provides information about the Environment class. The Environment class is used when your compiler does not support exceptions through the try and catch statements.

For Platforms without C++ Exception Support

Not all C++ compilers support exceptions through the try and catch statements, so the CORBA specification defines an Environment class for reflecting exceptions. ISB for C++ uses the Environment class, along with a set of macros, to provide your applications with exception handling capabilities when try and catch are not supported.

The Exception Macros

The Environment class is used internally by the ORB and is transparent to you as a programmer. The only requirement is that you use these exception macros to throw, try and catch exceptions. These macros will transparently manipulate the Environment class for you if your compiler does not support exceptions.

Table 11.14 The PMC exception Macros.
Macro Name Purpose
PMCTRY

Use this as you would use the try statement.

PMCTHROW(type_name)

Throws the specified exception.

PMCTHROW_LAST

Used to re-throw the specified exception. Used only in an event handler or in a method called by an event handler.

PMCCATCH(type_name, variable_name)

Use this to catch an exception of the specified type.

PMCAND_CATCH

If several exceptions are to be specified for a PMCTRY block, use PMCCATCH for the first catch statement and PMCAND_CATCH for all subsequent catch statements.

PMCEND_CATCH

Used to terminate a PMCTRY block.

Using the Exception Macros

The following code example shows how to use the compatibility exception macros.

Using the compatibility macros to catch a system exception.

....
library *library_object;
PMCTRY {
   library_object = library::_bind();
}
// Check for errors
PMCCATCH(CORBA::SystemException excep) {
   cout << "System Exception occurred:" << endl;
   cout << "Exception name:  " << excep._name() << endl;
   cout << "Minor code:      " << excep.minor() << endl;
   cout << "Completion code: " << excep.completed() << endl;
}
PMCENDCATCH
...

Object Implementation Considerations

The IDL compiler detects whether or not your C++ compiler supports exceptions and generates code accordingly. The sample code below would appear as follows for a compiler without C++ support. Note that the throw statement is not generated.

virtual CORBA::Boolean   add_book(const book& book_info);
The object's implementation of add_book would use PMCTHROW to raise the exception.

CORBA::Boolean Library::add_book(const book& book_info)
{
   CORBA::Boolean ret;
   if( (ret = bk_list.add_to_list(book_info)) == 0 )
      PMCTHROW (library::CapacityExceeded();)
   return ret;
}


[Previous] [Contents]

Last Updated: 02/03/98 15:34:36


Copyright © 1997 Netscape Communications Corporation

Any sample code included above is provided for your use on an "AS IS" basis, under the Netscape License Agreement - Terms of Use