Create user-defined exception objects

Note

Now you create two user-defined exception objects that you will throw from a function that is invoked when the user clicks the command button on the w_cust_pct window. You also create a user-defined exception object that you throw from a user event on the drop-down list box control that you added to the w_cust_pct window.

  1. Select File>New from the PowerBuilder menu and click the PBObject tab in the New dialog box.

  2. Select the Standard Class icon and click OK.

    Select throwable from the Types list box and click OK.

    The new exception object displays in the User Object painter.

  3. In the Text box of the Properties view, type the following:

    No rows were returned from the database. If you typed or selected a state code in the drop-down list box and the database connection has not been closed, either the state you entered has no customers or you entered the state code incorrectly. 
    

    The exception object has get and set methods for handling the Text property. Here you set the text property directly in the user interface.

  4. Click outside the Properties view to enable the Save button.

    Select File>Save, select the pbtutor.pbl application library, and type exc_no_rows in the User Objects box for the new exception object name, and click OK.

  5. Select File>Close.

  6. Repeat steps 1-5 using the following values for the Text property and the exception object name:

    Property

    Value

    Text

    Percentage too low. Only one customer in this state. Notify regional sales manager...

    Exception object name

    exc_low_number

  7. Repeat steps 1-5 using the following values for the Text property and the exception object name:

    Property

    Value

    Text

    You must use the two-letter postal code for the state name.

    Exception object name

    exc_bad_entry