Thursday, July 26, 2007

Handling Exceptions

CORBA Exception Handling Concepts
1. System exceptions - which are general errors
2. User exceptions - triggered by an object

CORBA System Exceptions
example BAD_CONTEXT - An error occured while processing context objects

The Exception class provides the following public operations:
copy constructor
destructor
_narrow
Copy constructor and destructor operations automatically manage the storage associated with the exception.
The _narrow operation allows your CORBA client application to catch any type of exception and then determine its type.
The exception argument passed to the _narrow operaton is a pointer to the base class Exception. If the pointer of type SystemException, the narrow() operation returns a pointer to the exception, otherwise it returns a Null pointer.

Handling System Exceptions

try
{
//Initialize the ORB
CORBA::ORB* orb=CORBA::ORB_init(argc, argv, ORBid);

//Get a Bootstrap Object
Tobj_Bootstrap* bs= new Tobj_Bootstrap(orb, "//host:port");

//Resolve Factory Finder
CORBA::Object_var var_factory_finder_oref = bs->resolve_initial_reference("FactoryFinder");
Tobj::FactoryFinder_var var_factory_finder_ref = Tobj::FactoryFinder::_narrow(var_factory_finder_oref.in());
catch(CORBA::Exception& e)
{
cerr <<e.get_id()>< User Exceptions
The code should first check for system exceptions, and often the application cannot recover from system exception.

the sample shows how a TooManyCredits user exception would work within the scope of a transaction for registering for classes.

try
{
pointer_registrar_reference->register_for_courses(student_id, course_number_list);
catch (UniversityT::TooManyCredits& e)
{
cout <<"You cannot register for more than"<<>
}

No comments: