SAM::Exception and the new Status Manager
In order to convert your existing SAMDbServer code to use the new SAM::Exception model, or develop new code for this new model, you can simply follow these tips.
- What you now have to do - FIRST:
- Make sure you have the correct version of these products checked out in your area.
- What you now have to do (in the idl layer):
- Add new SEC_DBXxxx type SAMErrorCodes to the SAMErrorCode.idl file in sam_common_idl/sam_common. This is a new set of error codes. Most of the existing DbServer exceptions have already been added here, but check to be certain before you assume that there is a SEC_DBSomethingNotFound. When adding new SEC's, notice that the syntax to follow is to add them of the naming convention SEC_DBMyNewException for mapping of an internal layer InMyNewException.
Igor recommends we put them at the bottom, but I'm not so sure that this matters. We will see!!!!
- In your IDL where you want to use the new exceptions:
- raise SAM::Exception, which is defined in sam_common_idl/sam_common/Status.idl. For an example IDL file, see Db2Station.idl, specifically the getPhysicalFileInfo method.
- Add the following #include lines:
- What you now have to do (on the server side):
- Add new InXXX exceptions to InExceptions.py, just like you did before.
- Change your exception catching in your Impl layer code from
raise self.xMap.StatusMap(sys.exc_info(), self.__class__.__name__)
where the second argument above is the class name for use in the output message text.
- For an example of this, see the StationImpl.py file in sam_db_server.
- Make sure SAM and SAM_skel are imported into your Impl code.
- Make sure your server sets up sam_common. The new ups file in sam_db_server now does this.
- What is done for you already (on the server), so you don't have to do:
- DO NOT modify ExceptionMap.py in sam_db_server/src. This was already modified to map exceptions from the InXXX type to the SAM::Exception type. Even if you are now creating new exceptions, you will NOT have to modify this file anymore.
- DO NOT modify SAMDbException.idl in sam_db_server_idl/sam_db_server. These SAMDbServer type exceptions are no longer needed in the new exception mapping scheme. And, any existing SAMDbServer exceptions will be properly mapped when you choose to use the new scheme.
- DO NOT change any of your existing InXXX exception raising. Raise them all as you do now and they are automatically mapped to the SAM::Exception model.
- What you now have to do (on the client side - for python clients):
- Make sure your client sets up sam_common.
- import StatusMan_srep into your client code.
- Catch exceptions like this...
except SAM.Exception, ex:
This will result in output similar to the following:
Code: SEC_DBStationNotFound (Category User)
Severity level: ERROR
Generated on Mon Jan 18 21:14:07 2038 by DB server
In the context: StationImpl.getGroups: local(Station not found with id '-1'.)
Recommended action: Please check your data, contact firstname.lastname@example.org
Additional information: Any more info that is provided with the error.
- What you now have to do (on the client side - for C++ clients):
- Talk to Igor or some other SAM C++ expert!
Last modified: Wed Mar 7 17:27:36 CST 2001