Error Handling With Trees
The tree classes log descriptive information regarding errors and warnings to the PSMessages collection, instantiated from a session object.
In your program, use the PSMessages collection to identify and report to the user any errors that are encountered during processing.
The tree classes log errors "interactively", that is, as they happen. For example, suppose you had created a new tree, and were setting the effective date using the effective date property (EffDt). If you used an invalid value for the effective date, the error would be logged in the PSMessages collection as soon as you set the value, not when you saved the tree.
When you want to check for errors depends on your application. However, if you check for errors after every assignment, you may see a performance degradation.
One way to check for errors is to check the number of messages in the PSMessages collection, using the Count property. If the Count is 0, no error or warning messages have been logged to the PSMessages collection.
Local ApiObject &MYSESSION; Local ApiObject &ERRORCOL; Local ApiObject &TREE, TREELIST; &MYSESSION = %Session; If &MYSESSION Then /* connection is good */ &MyTree = &Session.GetTree(); /* open a tree */ &TreeReturn = &MyTree.Open("", "", "PERSONAL_DATA", "1999-06-01", "",true); /* Do error checking */ &ERRORCOL = &MYSESSION.PSMessages; If (&ERRORCOL.Count <> 0) Then /* errors occurred - do processing */ Else /* no errors */ End-If; Else /* do processing for no connection */ End-If;
You can also do an error check based on the return value of your API calls
If ALL(&TreeReturn) then /* processing errors */ End-if: