Error

Description

PowerBuilder

Occurs when an error is found in a data or property expression for an external object or a DataWindow object. Also occurs when a communications error is found in a distributed application.

PowerBuilder event information

Event ID: None

Argument

Description

errornumber

Unsigned integer by value (PowerBuilder's error number).

errortext

String, read-only (PowerBuilder's error message).

errorwindowmenu

String, read-only. The name of the window or menu that is the parent of the object whose script caused the error.

errorobject

String, read-only. The name of the object whose script caused the error.

errorscript

String, read-only. The full text of the script in which the error occurred.

errorline

Unsigned integer by value. The line in the script where the error occurred.

action

ExceptionAction by reference.

A value you specify to control the application's course of action as a result of the error. Values are:

  • ExceptionFail! -- Fail as if this script were not implemented. This is the default action. The error condition triggers the SystemError event if you do not handle the error in a Try-Catch block.

  • ExceptionIgnore! -- Ignore this error and return as if no error occurred. Use this option with caution because the conditions that caused the error can cause another error.

  • ExceptionRetry! -- Execute the function or evaluate the expression again in case the OLE server was not ready. This option is not valid for DataWindows.

  • ExceptionSubstituteReturnValue! -- Use the value specified in the returnvalue argument instead of the value returned by the OLE server or DataWindow and cancel the error condition.

returnvalue

Any by reference. A value whose datatype matches the expected value that the OLE server or DataWindow would have returned.

This value is used when the value of action is ExceptionSubstituteReturnValue!.


Return Values

None. (Do not use a RETURN statement.)

Usage

DataWindow and OLE objects are dynamic. Expressions that use dot notation to refer to data and properties of these objects might be valid under some runtime conditions but not others. The Error event allows you to respond to this dynamic situation with error recovery logic.

The Error event also allows you to respond to communications errors in the client component of a distributed application. In the Error event for a custom connection object, you can tell PowerBuilder what action to take when an error occurs during communications between the client and the server.

The Error event gives you an opportunity to substitute a default value when the error is not critical to your application. Its arguments also provide information that is helpful in debugging. For example, the arguments can help you debug DataWindow data expressions that cannot be checked by the compiler -- such expressions can only be evaluated at runtime.

When to substitute a return value

The ExceptionSubstituteReturnValue! action allows you to substitute a return value when the last element of an expression causes an error. Do not use ExceptionSubstituteReturnValue! to substitute a return value when an element in the middle of an expression causes an error. The substituted return value will not match the datatype of the unresolved object reference and will cause a system error.

The ExceptionSubstituteReturnValue! action is most useful for handling errors in data expressions.

For DataWindows, if an error occurs while evaluating a data or property expression, error processing occurs like this:

  1. The Error event occurs.

    If you use a Try-Catch block, it is best not to script the Error event.

  2. If the Error event has no script or its action argument is not changed from the default action (ExceptionFail!), either a catch statement is executed or the SystemError event occurs.

  3. If you do not handle the error in a Try-Catch block and the SystemError event has no script, an application error occurs and the application is terminated.

The chapter on "Using DataWindow Objects" in the DataWindow Programmers Guide contains a table of correspondences between Error event arguments and DWRuntimeError properties. You can use the DWRuntimeError properties in a Try-Catch block to obtain the same information about an error condition that you would otherwise obtain from Error event arguments.

For information about error processing in OLE controls, see the ExternalException event description in the section called “ExternalException” in PowerScript Reference.

For information about using data and property expressions for DataWindow objects, see Accessing Data in Code and Accessing DataWindow Object Properties in Code

Examples

This example displays information about the error that occurred and allows the script to continue:

MessageBox("Error Number " + string(errornumber)&
      + " Occurred", "Errortext: " + String(errortext))
action = ExceptionIgnore! 

See also

DBError