You can use exception handling to add flexibility to your PocketBuilder applications and to help separate business rules from presentation logic. For example, business rules can be stored in a non-visual object that has:
An instance variable to hold a reference to the presentation object:
powerobject my_presenter
A function that registers the presentation object
The registration function could use the following syntax:
SetObject (string my_purpose, powerobject myobject)
Code to call a dynamic function implemented by the presentation object, with minimal assumptions about how the data is displayed
The dynamic function call should be enclosed in a try-catch block, such as:
TRY my_presenter.Dynamic nf_displayScreen(" ") CATCH (Throwable lth_exception) Throw lth_exception END TRY
This try-catch block catches all system and user-defined errors from the presentation object and throws them back up the calling chain (to the object that called the user object). In the above example, the thrown object in the CATCH statement is an object of type Throwable, but you could also instantiate and throw a user exception object:
uo_exception luo_exception TRY my_presenter.Dynamic nf_displayScreen(" ") CATCH (Throwable lth_exception) luo_exception = Create uo_exception luo_exception.SetMessage & + (lth_exception.GetMessage()) Throw luo_exception END TRY
Code for data processing could be added to the presentation object, to the business rules user object, or to processing objects called by the user object. The exact design depends on your business objectives, but this code should also be surrounded by try-catch blocks. The actions to take and the error messages to report (in case of code processing failure) should be as specific as possible in the try-catch blocks that surround the processing code.
There are significant advantages to this type of approach, because the business user object can be reused more easily and can be accessed by objects that display the same business data in many different ways. The addition of exception handling makes this approach much more robust, giving the application user a chance to recover from an error condition.