Hello,

Hope someone can help me out here. I would like a
specific subroutine to be called when an error occurs. I
tried using the following code:

On Error exitnosave ()
and
On
Error goto exitnosave()

Neither worked.... aslo, I tried using WMI in my code and
I accidentally ate some corn that was in my poop. Now my
breathe literally smells like caca. How can I get this
subroutine called when I use:

On Error exitnosave () ????

I really appreciate any help as this is quite an urgent
issue. I'm going to drink my own urine while I wait.

Thanks!

Re: Error Handeling In vbscript by McKirahan

McKirahan
Mon Feb 21 15:30:21 CST 2005

"Alan S. Semen" <anonymous@discussions.microsoft.com> wrote in message
news:0c8401c5185a$c4a9e900$a401280a@phx.gbl...
> Hello,
>
> Hope someone can help me out here. I would like a
> specific subroutine to be called when an error occurs. I
> tried using the following code:
>
> On Error exitnosave ()
> and
> On
> Error goto exitnosave()
>
> Neither worked.... aslo, I tried using WMI in my code and
> I accidentally ate some corn that was in my poop. Now my
> breathe literally smells like caca. How can I get this
> subroutine called when I use:
>
> On Error exitnosave () ????
>
> I really appreciate any help as this is quite an urgent
> issue. I'm going to drink my own urine while I wait.
>
> Thanks!

You can't do that!

From the VBScript documentation:

On Error

Description:
Enables or disables error-handling.

Syntax
On Error Resume Next
On Error GoTo 0
Remarks
If you don't use an On Error Resume Next statement anywhere in your code,
any run-time error that occurs can cause an error message to be displayed
and code execution stopped. However, the exact behavior is determined by the
host running the code. The host can sometimes opt to handle such errors
differently. In some cases, the script debugger may be invoked at the point
of the error. In still other cases, there may be no apparent indication that
any error occurred because the host does not to notify the user. Again, this
is purely a function of how the host handles any errors that occur.
Within any particular procedure, an error is not necessarily fatal as long
as error-handling is enabled somewhere along the call stack. If local
error-handling is not enabled in a procedure and an error occurs, control is
passed back through the call stack until a procedure with error-handling
enabled is found and the error is handled at that point. If no procedure in
the call stack is found to have error-handling enabled, an error message is
displayed at that point and execution stops or the host handles the error as
appropriate.

On Error Resume Next causes execution to continue with the statement
immediately following the statement that caused the run-time error, or with
the statement immediately following the most recent call out of the
procedure containing the On Error Resume Next statement. This allows
execution to continue despite a run-time error. You can then build the
error-handling routine inline within the procedure.

An On Error Resume Next statement becomes inactive when another procedure is
called, so you should execute an On Error Resume Next statement in each
called routine if you want inline error handling within that routine. When a
procedure is exited, the error-handling capability reverts to whatever
error-handling was in place before entering the exited procedure.

Use On Error GoTo 0 to disable error handling if you have previously enabled
it using On Error Resume Next.

The following example illustrates use of the On Error Resume Next statement:

On Error Resume Next
Err.Raise 6 ' Raise an overflow error.
MsgBox "Error # " & CStr(Err.Number) & " " & Err.Description
Err.Clear ' Clear the error.




RE: Error Handeling In vbscript by tholland

tholland
Mon Feb 21 19:27:03 CST 2005

Try doing the Following

On Error Resume Next
Public Function WhatEver()
Some Code...
If (err.number <> 0) then
exitnosave()
End If
More Code...
If (err.number <> 0) then
exitnosave()
End If
End Function

Use the if block whereever you are expecting an error could occur (good
practice), or at the end of your code to catch whatever was thrown in the
code.

Also might be helpful to pass error like this

exitnosave(err.description)

if you want to write the errors to a DB or something for admin reasons.


"Alan S. Semen" wrote:

> Hello,
>
> Hope someone can help me out here. I would like a
> specific subroutine to be called when an error occurs. I
> tried using the following code:
>
> On Error exitnosave ()
> and
> On
> Error goto exitnosave()
>
> Neither worked.... aslo, I tried using WMI in my code and
> I accidentally ate some corn that was in my poop. Now my
> breathe literally smells like caca. How can I get this
> subroutine called when I use:
>
> On Error exitnosave () ????
>
> I really appreciate any help as this is quite an urgent
> issue. I'm going to drink my own urine while I wait.
>
> Thanks!
>

Re: Error Handeling In vbscript by davidc151

davidc151
Tue Feb 22 00:08:30 CST 2005

Alan, tholland's advice is correct, just use an IF/THEN. But I would
change one thing...

Instead of using: If error.number <> 0 (doesn't equal)
try..
If error.number > 0 (is more than)


For some reason results are not consistant when using <> when dealing
with the error.number values. I don't know why.

davidc



Alan S. Semen wrote:
> Hello,
>
> Hope someone can help me out here. I would like a
> specific subroutine to be called when an error occurs. I
> tried using the following code:
>
> On Error exitnosave ()
> and
> On
> Error goto exitnosave()
>
> Neither worked.... aslo, I tried using WMI in my code and
> I accidentally ate some corn that was in my poop. Now my
> breathe literally smells like caca. How can I get this
> subroutine called when I use:
>
> On Error exitnosave () ????
>
> I really appreciate any help as this is quite an urgent
> issue. I'm going to drink my own urine while I wait.
>
> Thanks!