ExternalException event
Description
Occurs when an OLE automation command caused an exception
on the OLE server.
Improved error-handling capability in PowerBuilder
The ExternalException event is maintained for backward compatibility.
If you do not script this event or change its action argument, information
from this event is passed to RuntimeError objects, such as OLERuntimeError.
You can handle these errors in a try-catch block.
Event ID
|
Event ID |
Objects |
|---|---|
|
None |
OLE, OLEObject, OLETxnObject |
Parameters
|
Argument |
Description |
|---|---|
|
resultcode |
UnsignedLong by |
|
exceptioncode |
UnsignedLong by |
|
source |
String by value |
|
description |
String by value |
|
helpfile |
String by value |
|
helpcontext |
UnsignedLong by |
|
action |
ExceptionAction by reference. A value you specify to control the application’s
|
|
returnvalue |
Any by reference. A value whose datatype matches the expected value that the OLE |
Return Values
None. (Do not use a RETURN statement.)
Usage
OLE objects are dynamic. Expressions that refer to data and
properties of these objects might be valid under some runtime conditions
but not others. If the expression causes an exception on the server,
PowerBuilder triggers the ExternalException event. The ExternalException
event gives you information about the error that occurred on the
OLE server.
The server defines what it considers exceptions. Some errors,
such as mismatched datatypes, generally do not cause an exception
but do trigger the Error event. In some cases you might not consider
the cause of the exception to be an error. To determine the reason
for the exception, see the documentation for the server.
When an exception occurs because of a call to an OLE server,
error handling occurs like this:
-
The ExternalException
event occurs. -
If the ExternalException event has no script or
its action argument is set to ExceptionFail!,
the Error event occurs. -
If the Error event has no script or its action argument
is set to ExceptionFail!, any active exception handler for an OLERuntimeError
or its RuntimeError ancestor is invoked. -
If no exception handler exists, or if the existing
exception handlers do not handle the exception, the SystemError
event is triggered. -
If the SystemError event has no script, an application
error occurs and the application is terminated.
Examples
Suppose your window has two instance variables: one
for specifying the exception action, and another of type Any for
storing a potential substitute value. Before accessing the OLE property,
a script sets the instance variables to appropriate values:
|
1 |
ie_action = ExceptionSubstituteReturnValue! |
|
1 |
ia_substitute = 0 |
|
1 |
li_currentsetting = ole_1.Object.Value |
If the command fails, a script for the ExternalException
event displays the Help topic named by the OLE server, if any. It
substitutes the return value you prepared and returns control to
the calling script. The assignment of the substitute value to li_currentsetting works
correctly because their datatypes are compatible:
|
1 |
string ls_context |
|
1 |
|
1 |
// Command line switch for WinHelp numeric context ID |
|
1 |
ls_context = "-n " + String(helpcontext) |
|
1 |
If Len(HelpFile) > 0 THEN |
|
1 |
   Run("winhelp.exe " + ls_context + " " + helpfile) |
|
1 |
END IF |
|
1 |
|
1 |
action = ie_action |
|
1 |
returnvalue = ia_substitute |
Because the event script must serve for every automation command
for the control, you need to set the instance variables to appropriate
values before each automation command.