Re: VBScript Newbie: Error Handling, Forwarding an Error

Tech-Archive recommends: Speed Up your PC by fixing your registry



Also, a VBScript program can return an error number to the calling program
(a batch file or some exe's) with the Quit method of the Wscript object. For
example:
==========
' Return error code 2.
Wscript.Quit(2)

' Return zero, which means no error.
Wscript.Quit
=========
The number returned by Quit can be tested in a batch file using ERRORLEVEL.
I have also returned error conditions to some setup programs with this.

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net

"joes" <joes@xxxxxxxxxx> wrote in message
news:1163511350.102998.151900@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Many thanks, Danke vielmals ; )
That was exactly what I needed

best regards
Mark

ekkehard.horner schrieb:

joes wrote:
I am using a third party application which allows to embed at some
places VBScript. This application already has an errorhandling which I
can not change (compiled exe).

My idea is that I implement for my own embedded VB Code my own
errorhandling and in some cases forwarding th error to the existing
error handling of the third party application. How can I achieve that
in VBScript? i.e. Can I retrieve somehow the existing "On Error XXX "
setting before I overwrite it? Or do you know some VB possiblities
which I don't know like Try/Catch in other languages?

Many thanks in advance
Mark Egloff

'My Error Handling Pseudo Code

On Error Resume Next
If Err.Number <> 0 Then
'Filter Errors
If Err.Number = .... Then
'forward it to "previous" error handling...
?????? Forward Err ?????
'else ....

End If

End If

A very simple approach: save the (important) Err.Properties, handle some
errors yourself, Err.Raise fatal errors:

Dim nErr, aErr
For Each nErr In Array( 429, 7 )
On Error Resume Next
Err.Raise nErr ' fake some error
aErr = Array( Err.Number, Err.Description )
On Error GoTo 0
Select Case aErr( 0 )
Case 0 ' can't be simulated: Err.Raise 0 =>
' Ungültiger Prozeduraufruf oder ungültiges Argument
WScript.Echo nErr, "No error, no action"
Case 429 ' 429 ActiveX-Komponenten kann kein Objekt erstellen
WScript.Echo _
"*** Let's ignore this - who needs those ActiveX components
anyway **"
Case 7 ' 7 Nicht genügend Arbeitsspeicher.
WScript.Echo "*** nothing I can do **"
Err.Raise aErr( 0 ), "raised again in Sub Whatever()", aErr( 1 )
Case Else
WScript.Echo aErr( 0 ), aErr( 1 )
WScript.Echo "*** Decide how you want to handle this ***"
End Select
Next

output:

=== ErrRaise: raise error again (sometimes)
===================================
*** Let's ignore this - who needs those ActiveX components anyway **
*** nothing I can do **
C:\programme\bin\xplore.wsf(0, 2) raised again in Sub Whatever(): Nicht
genügend
Arbeitsspeicher.

For a more elaborate/elegant solution search for "Error" and "Justin
Piper" in this
group.


.



Relevant Pages

  • Re: Rollout Registry Settings via SMS (w/Adv Clients)
    ... success code of 0 is returned post-install, then a reg import is run. ... so I went with DFS. ... import, or because I'm a vbscript person, I'd probably write a vbscript to ... batch file can point to the DFS share where the registry entries are located. ...
    (microsoft.public.sms.swdist)
  • Re: UNIX tr utility written in vbscript
    ... A batch file can run a VBScript program, and you can pass the name of the VBScript to the batch file as a parameter. ... write a batch script that creates the vbscript file to be called. ... This should be located in %temp% where the user will have the required permissions, and where two concurrent users will not interfere with each other. ...
    (microsoft.public.scripting.vbscript)
  • Re: A few questions for you VBScript Gurus!!!
    ... >> I am new to VBScript and was hoping for some pointers. ... >> batch file works like a dream, however, I would like to use VBScript to ... the script will carry on to the next line of code. ... >> if a certain condition was met, goto label, If condition wasn't met ...
    (microsoft.public.scripting.vbscript)
  • Re: Launch batch file and pass control back to VBScript
    ...    Exit Do ... This script essentially launches the batch file ... because it appears that control is still in the "startserver" ... control is never passed back to the VBScript. ...
    (microsoft.public.scripting.vbscript)
  • Re: Xcopy /D copies all files, not just newer
    ... OP already said they were writing a batch file, so I recommend vbscript. ... Why use built in commands if the issue here is a built in command was ... Xcopy and Robocopy have around 50 switches. ...
    (microsoft.public.windows.vista.general)