Connection Information

To perform the requested action, WordPress needs to access your web server. Please enter your FTP credentials to proceed. If you do not remember your credentials, you should contact your web host.

Connection Type

Handling errors from DataWindow property expressions in PowerBuilder – PB Docs 2022 – PowerBuilder Library

Handling errors from DataWindow property expressions in PowerBuilder – PB Docs 2022

Handling errors from DataWindow
property expressions in PowerBuilder

What causes errors

In PowerBuilder, an invalid DataWindow property expression causes
a runtime error in your application. A runtime error causes the
application to terminate unless you catch the error in a runtime error
handler or unless there is a script for the Error event.

Conditions that cause errors

Possible causes

Invalid names of controls within the DataWindow
object

Mistyping, which the compiler does not catch
because it does not evaluate the expression.

A
different DataWindow object has been inserted in the control and
it has different columns and controls.

A property is not valid for the specified
control

Mistyping.

The control is a different
type than expected.

You can prevent the application from terminating by handling the
error in the DataWindow control’s Error event or by catching the error
in a try-catch block.

Responding to errors in the Error event
script

The Error event’s arguments give you several options for
responding to the error. You choose a course of action and set the
action argument to a value of the ExceptionAction enumerated
datatype.

ExceptionAction enumerated datatype

If you give the action argument a value other than
ExceptionIgnore!, you will prevent error-handling code in try-catch
blocks from executing. For more information on values for the
ExceptionAction enumerated datatype, see the Error event description
in the the section called “Error” in PowerScript Reference.

If you are trying to find out a property value and you know the
expression might cause an error, you can include code that prepares for
the error by storing a default value in an instance variable. Then the
Error event script can return that value in place of the failed
expression.

There are three elements to this technique: the declaration of an
instance variable, the script that sets the variable’s default value and
then accesses a DataWindow property, and the Error event script. These
elements are shown in Example 2 below.

Responding to errors in a try-catch
block

You can prevent the application from terminating by handling the
DataWindow runtime error (DWRuntimeError) in a try-catch block. If you
are trying to find out a property value and you know the expression
might cause an error, you can include code that automatically assigns a
valid default value that can be substituted for the failed expression,
as in Example 2 below.

Examples

Example 1

This code displays complete information about the error in a
multilineedit mle_1.

The error event script:

The try-catch block:

If the correct evaluation of the expression is not critical to the
application, the application continues without terminating.

Example 2

This example provides a return value that will become the
expression’s value if evaluation of the expression causes an
error.

There are three elements to code in the error event script. The
instance variable is a string:

This script for a button or other control stores a valid return
value in an instance variable and then accesses a DataWindow
property:

The Error event script uses the instance variable to provide a
valid return value:

The try-catch block:

At runtime, if the id column does not exist or some other error
occurs, then the expression returns a valid border value — here the
string “5”. If you are using the Error event instead of a try-catch
block, you must first store the value in an instance variable.


Document get from Powerbuilder help
Thank you for watching.
Was this article helpful?
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x