Mastering PowerBuilder DataWindow
Dot Notation - Error Handling
When
you use the ".Object" convention, the compiler checks
the syntax only till "Object". Everything following the
Object property is evaluated at execution time. PowerBuilder
triggers the DataWindow control's Error event whenever an error
occurs in the expression at execution time. The Error event
allows you to respond with error recovery logic when an expression
is not valid. If you write a script for this event, you can catch an
error before it triggers the "SystemError" event at the application object.
For example:
dw_product.Object.Data[
dw_product.GetRow(),2] = &
'obsolete ' + &
dw_product.Object.Data[ dw_product.GetRow(),2] |
In
the above expression, we are marking a product obsolete by
prefixing "obsolete" to the product_description. The
above code assumes the "product_description" would be
the second column in the DataWindow. Just for testing, replace 2
with 1 and append this code to the ue_retrieve event of the
w_product_master and run the application. You won't get the
compilation error and will get run-time error. Since, we wrote no code
for the "Error" event for the dw_product
DataWindow control, this error will trigger "SystemError" event.
The "Error" event has several
arguments that provide information about the error condition. The
first five arguments in the following listing are the same as the
attributes that are available at error object.
 |
errornumber |
 |
errortext |
 |
errorwindowmenu |
 |
errorobject |
 |
errorscript |
 |
errorline |
 |
action |
 |
returnvalue |
The
last two arguments "action" and "ReturnValue"
are passed by reference that allow you to affect the outcome of
the event. You can specify one of the following four values for
the action:
 |
ExceptionFail! |
 |
ExceptionIgnore! |
 |
ExceptionRetry! |
 |
ExceptionSubstituteReturnValue! |
The
default value for action is "ExceptionFail!". That means, if you
don't write any code for this event, action contains
ExceptionFail!. This value triggers "SystemError" event. You can populate
"ReturnValue" with a value whose data type matches the
expected value that the DataWindow would have returned. This
value is used when the value of "action" is ExceptionSubstituteReturnValue!
Do not use ExceptionSubstituteReturnValue! to substitute a return
value when an element in the middle of an expression causes an
error. The ExceptionSubstituteReturnValue! is most useful for
handling errors in data expressions.
|