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 operation is a pointer to the base class
Exception. The
_narrow operation accepts a pointer to any Exception object. If the pointer is of type
SystemException, the
narrow() operation returns a pointer to the exception. If the pointer is not of type
SystemException, the
narrow() operation returns a
Null pointer.
Unlike the _narrow operation on object references, the
_narrow operation on exceptions returns a suitably typed pointer to the same exception argument, not a pointer to a new exception. Therefore, you do not free a pointer returned by the
_narrow operation. If the original exception goes out of scope or is destroyed, the pointer returned by the
_narrow operation is no longer valid.
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() <<end1;
}
exception TooManyCredits
{
unsigned short maximum_credits;
};
interface Registrar
NotRegisteredList register_for_courses(
in StudentId student,
in CourseNumberList courses
) raises (
TooManyCredits
);
//Register a student for some course
try {
pointer_registrar_reference->register_for_courses
(student_id, course_number_list);
catch (UniversityT::TooManyCredits& e) {
cout <<"You cannot register for more than"<< e.maximum_credits
<<"credits."<<end1;
}