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

The Exception Macros

Using the Exception Macros

Object Implementation Considerations

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. VisiBroker 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.

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

You can modify the application client code shown in Catching System Exceptions to use the compatibility macros. The following example shows the modifications in bold type.


	....

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 object implementation code shown in Defining User Exceptions 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; }


[Preface] [Chapter 1] [Chapter 2] [Chapter 3] [Chapter 4] [Chapter 5] [Chapter 6]
[Chapter 7] [Chapter 8] [Chapter 9] [Chapter 10] [Chapter 11] [Chapter 12] [Appendix A]