Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Need help with OLE Exception handling!

85 views
Skip to first unread message

Elias Kalomiris

unread,
Aug 25, 1999, 3:00:00 AM8/25/99
to
I'm trying to catch a particular error code from an Access OLE object
BEFORE PB 6 triggers the systemerror event and halts program execution.
I have already coded an error event in my OLE object but this event
never gets triggered.
Specifically: I'm using OLE to open a report in Access. This
particular report shows a calandar which the user has the option of
cancelling (thereby cancelling the report as well). The report is coded
to return a cancel code if the user does this. The problem is that when
I call DoCmd.OpenReport and the user cancels, PB immediately triggers
the systemerror event (R1037) "Error calling external object function
OpenReport".
Does anyone know how I can gracefully catch this exception. Thanks
in advance.


Oliver Willandsen [European Commission]

unread,
Aug 26, 1999, 3:00:00 AM8/26/99
to

On Wed, 25 Aug 1999 17:40:28 +0300,
in powersoft.public.powerbuilder.ole-ocx-activex


Hi Elias,

trapping errors for OLE automation is a rather complicated affair. Your example
actually
generates error number 35 - which, according to MS document 'Trappable errors'
in the
MSDN knowledge base, is 'sub, function or property not defined'. I would take
that to suspect
a wrong call to the open method - and that is what is indeed returned to the PB
error object,
namely 'error calling external function call open'. So far so good. However,
changing the method
invocation by passing it all the ( normally) optional arguments, as in
loo_oleobject.application.Documents.Open("c:\xxx.doc"), False, False, False,
False, "", "",
False, "", "", 1) where the parameters passed aren't the ones Open expects, the
error
generated is 33 ( invalid parameter typer calling external function open ) - but
this error
is not referenced anywhere I could find. Article ID: Q186063 in the MSDN
knowledge base -
INFO: Translating Automation Errors for VB/VBA (Long) provides an interesting
insight into
the arcanes of MS error codes.

More to the actual point of your problem though - there seem to be some errors
such as the
aforementioned 35 and 33 which will trigger the systemerror event regardless of
what code
you might have provided in the externalexception and error events of your custom
oleobject, and the PB help states quite explicitly, and I quote

"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!, the
SystemError event occurs.
· If the SystemError event has no script, an application error occurs and
the application is
terminated.

All is not lost however, and to prove my point try the following:

gnv_app.of_SetSystemErrorTrap( True ) // set gnv_app.ib_no_systemerror to
TRUE

// connect the ole object to word
loo_oleobject = create sg_n_cst_oleobject

li_connection_returncode = loo_oleobject.ConnectToObject( "",
"Word.Application")

// do your returncode checking here

//Choose Case
// CASE -1
// ls_returnmessage = "Invalid call: the argument is the Object
property of a control"

// etc., etc.

IF li_connection_returncode <> 0 THEN

MessageBox( "OLE OBJECT CONNECTION ERROR", ls_returnmessage )

li_connection_returncode =
ioo_word.ConnectToNewObject("Word.Application")

IF li_connection_returncode <> 0 THEN

MessageBox( "OLE OBJECT CONNECTION ERROR", ls_returnmessage )

// disconnect the object
ioo_word.disconnectobject( )
// free the memory
destroy ioo_word
END IF
END IF

// create a new document
loo_oleobject.Application.Documents.Add ()

loo_oleobject.Selection.InsertAfter( "Some text" )

----

run the debugger and set a breakpoint on the last line above, once arrived
at this breakpoint,
switch to word and close the active document

switch back to PB and continue debugging


----

// close the active document
loo_oleobject.ActiveWindow.Close( 0 )


------

the above of course will fail, as you've just closed the active document
manually in Word
itself, but it will also _raise an oleobject exception_ !

So it will _first_ fire the externalexception event with resultcode 4248 -
this command is
not available bacause no document is open ( sounds logical ) _then_ it will
fire the error event
raising error 539 - error accessing external property activewindow ( logical
again ) and then
it will fire the systeerror event where of course you will have coded the
following

------
If gnv_app.of_GetSystemErrorTrap() Then Return


So in essence, it's not at all straighforward to deal with error trapping
for OLE automation -
but it's possible.


HTH
Oliver Willandsen [http://www.europa.eu.int]
European Commission - Remove PAS_DE_PUB to reply by Email

0 new messages