06-06-2006 12:45 PM
On Error Resume Next
On Error GoTo 0
06-07-2006 01:58 AM
Hi
There is an Err object to get or clear the last error. Search for "Err Object" in the help:
On Error Resume Next
Err.Raise 6 ' Raise an overflow error.
MsgBox ("Error # " & CStr(Err.Number) & " " & Err.Description)
Err.Clear ' Clear the error.
On other solution are some special Events: Try this small script. There is an spelling error in the second line but the Event_terminate event is executed properly.
Set SystemEvents = New SystemEventClass
Msgbx "hallo"
Class SystemEventClass
Private Sub Class_Initialize ' Initialize Event
Call MsgBoxDisp("Initialize")
End Sub
Private Sub Class_Terminate ' Terminate Event
Call MsgBoxDisp("Terminate")
End Sub
End Class
Hope this helps
Winfried
01-22-2020 02:53 AM
Hi, this is quite old, from 2006. Is there some similar way to handle errors as there is no support for handler in Diadem for "On Error goto handler"
and used in script:
....
exit sub
handler: here for example closing files
the event script doesnt work for me, the classes methods are executed, but the errror triggers after the terminate method, not opposite way, so its not usefull imho
01-22-2020 10:41 AM
Hi Lukas,
This is my preferred approach-- wrap only the "touchy action" inside the On Error structure, plus variable assignments to capture the reasons for the error. The Err object loses all its information as soon as On Error Goto 0 is executed, so trapping that info in variables is required. I find it VASTLY preferable to apply branching logic outside the On Error structure, so that any errors in the branching code can be found.
Dim ErrNum, ErrMsg, ErrSrc
On Error Resume Next
TouchyAction = 9/0
ErrNum = Err.Number
ErrMsg = Err.Description
Errsrc=Err.Source
On Error Goto 0
IF ErrNum <> 0 THEN Call YourTerminateSub(ErrNum, ErrMsg, ErrSrc)
' else proceed with the main script
LogFileWrite "--------------------"
LogFileWrite "Script finished without error!"
LogFileWrite "TouchyAction = " & TouchyAction
Sub YourTerminateSub(ErrNum, ErrMsg, ErrSrc)
LogFileWrite "--------------------"
LogFileWrite "ErrNum = " & ErrNum
LogFileWrite "ErrMsg = " & ErrMsg
LogFileWrite "Errsrc=" & ErrSrc
LogFileWrite "Terminating now..."
Call AutoQuit()
End Sub ' YourTerminateSub()
Brad Turpin
Senior Product Support Engineer
National Instruments