Doing Error Handling
All errors for the portal registry classes, like the other APIs, are logged in the PSMessages collection, instantiated from a session object.
The portal registry classes log errors that occur with methods immediately, and errors that occur with properties only after a method is executed.
For example, suppose you specified an invalid name when you were trying to delete a folder. The method (DeleteItem) returns False, and the error is logged in the PSMessages collection immediately.
Now suppose you created a new folder, and specified an invalid ValidTo date. The error won't be logged in the PSMessages collection until you tried to save your changes.
When you want to check for errors depends on your application. When users are entering data dynamically, and your program is registering their data in the portal, you may want to check for errors often. If you're using a batch program, you may want to check for errors only after the Open, Save, Insert, and Delete methods.
Most methods return a Boolean value indicating success or failure. After the failure of a method, you may want to check the PSMessages collection to determine the exact error.
Local ApiObject &MySession; Local ApiObject &ErrorCol; Local ApiObject &FolderCol, &Folder, &Registry; Local Boolean &Open;/* Access the current session */ &MySession = %Session; If &MySession Then /* connection is good */ &Registry = &MySession.GetRegistry(); &Open = &Registry.Open("CUSTOMER"); If &Open Then /* Registry opened successfully */ /* do processing */ Else /* Do error checking */ &ErrorCol = &MySession.PSMessages; For &I = 1 to &ErrorCol.Count /* do processing */ End-For; End-If; Else /* do processing for no connection */ End-If;