Re: VBScript Newbie: Error Handling, Forwarding an Error
- From: "Richard Mueller" <rlmueller-NOSPAM@xxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 14 Nov 2006 09:54:48 -0600
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 someA very simple approach: save the (important) Err.Properties, handle 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
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.
.
- References:
- VBScript Newbie: Error Handling, Forwarding an Error
- From: joes
- Re: VBScript Newbie: Error Handling, Forwarding an Error
- From: ekkehard.horner
- Re: VBScript Newbie: Error Handling, Forwarding an Error
- From: joes
- VBScript Newbie: Error Handling, Forwarding an Error
- Prev by Date: Re: How to set a AD Field Value in to a DOS Variable ?
- Next by Date: script to move an account from one group to another
- Previous by thread: Re: VBScript Newbie: Error Handling, Forwarding an Error
- Next by thread: Re: How to keep value
- Index(es):
Relevant Pages
|