Hi! :)

I want to return the err object from a function. How do I do this?

Do I have to create my own error class or is there a way to create an
instance/copy of the existing to return?

Thanks a million! :)

/Sofia

Re: Returning the Err object from a function by Dan

Dan
Wed Aug 16 10:31:12 CDT 2006

the ERR object has a global scope, so results are available outside of
your function. What are you trying to accomplish?

Re: Returning the Err object from a function by Sofia

Sofia
Wed Aug 16 12:11:44 CDT 2006

Hi Dan! :)

I use "On Error Goto 0" after the call to the function that might fail. This
clears Err automatically. I only use "On Error Resume Next" when theres a
function that I don't have control over. I want to get all other errors.
This means that I need to save the error message manually before the "On
Error Goto 0". Rather an error message than a script that doesn't function
as is should and me thinking it does.

I'm also doing other things between I'm getting the error and I want to
print the error message. I'm really just interested in Err.Number and
Err.Description. They are the ones I intend to put in my own little error
class if I don't get an answer. I just thought there might be a way to use
the existing class. :)

Thanks! :)

/Sofia


"Dan" <NoSpam@NoSpam.NoSpam> wrote in message
news:OgOdCkUwGHA.2120@TK2MSFTNGP03.phx.gbl...
> the ERR object has a global scope, so results are available outside of
> your function. What are you trying to accomplish?



Re: Returning the Err object from a function by Richard

Richard
Wed Aug 16 12:11:09 CDT 2006

Sofia Engvall wrote:

> I want to return the err object from a function. How do I do this?
>
> Do I have to create my own error class or is there a way to create an
> instance/copy of the existing to return?
>
> Thanks a million! :)

Hi,

You can use the Raise method of the error object to raise your own error. I
believe the syntax is:

Err.Raise(intNumber, "your source", "your description")

where intNumber is your error number. The error condition is maintained
until:

Err.Clear
On Error GoTo 0
On Error Resume Next

or a new error is raised.

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



Re: Returning the Err object from a function by Sofia

Sofia
Wed Aug 16 12:18:34 CDT 2006

Hi Richard! :)

Please read my reply to Dan.

Thanks! :)

/Sofia


"Richard Mueller" <rlmueller-NOSPAM@ameritech.NOSPAM.net> wrote in message
news:%235Ue7bVwGHA.2036@TK2MSFTNGP05.phx.gbl...
> Sofia Engvall wrote:
>
>> I want to return the err object from a function. How do I do this?
>>
>> Do I have to create my own error class or is there a way to create an
>> instance/copy of the existing to return?
>>
>> Thanks a million! :)
>
> Hi,
>
> You can use the Raise method of the error object to raise your own error.
> I believe the syntax is:
>
> Err.Raise(intNumber, "your source", "your description")
>
> where intNumber is your error number. The error condition is maintained
> until:
>
> Err.Clear
> On Error GoTo 0
> On Error Resume Next
>
> or a new error is raised.
>
> --
> Richard
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
>



Re: Returning the Err object from a function by ekkehard

ekkehard
Wed Aug 16 12:32:46 CDT 2006

Richard Mueller wrote:
> Sofia Engvall wrote:
>
>
>>I want to return the err object from a function. How do I do this?
>>
>>Do I have to create my own error class or is there a way to create an
>>instance/copy of the existing to return?
>>
>>Thanks a million! :)

Awhile ago I posted some demo code (Topic "Error handling bug on GetObject?");
perhaps this could you give some hints.

>
>
> Hi,
>
> You can use the Raise method of the error object to raise your own error. I
> believe the syntax is:
>
> Err.Raise(intNumber, "your source", "your description")

complete list of params according to the VBScript Docs:
object.Raise(number, source, description, helpfile, helpcontext)
(all params except number are optional)

the correct call would be:
object.Raise number, source, description, helpfile, helpcontext
NO param list () in VBScript Sub calls!

>
> where intNumber is your error number. The error condition is maintained
> until:
>
> Err.Clear
> On Error GoTo 0
> On Error Resume Next
>
> or a new error is raised.
>

Re: Returning the Err object from a function by Sofia

Sofia
Wed Aug 16 14:30:03 CDT 2006

Hi! :)

Replies below.

Thanks! :)

/Sofia

"ekkehard.horner" <ekkehard.horner@arcor.de> wrote in message
news:44e356be$0$6985$9b4e6d93@newsspool1.arcor-online.net...
> Richard Mueller wrote:
>> Sofia Engvall wrote:
>>
>>
>>>I want to return the err object from a function. How do I do this?
>>>
>>>Do I have to create my own error class or is there a way to create an
>>>instance/copy of the existing to return?
>>>
>>>Thanks a million! :)
>
> Awhile ago I posted some demo code (Topic "Error handling bug on
> GetObject?");
> perhaps this could you give some hints.

I found the topic at:
http://www.tutorialsall.com/VBSCRIPT/Error-handling-193562/.

From here: "21: saveErr = Array( Err.Number, Err.Source,
Err.Description )"
Are you suggesting that I put Err in an array?
If you read a few rows up you see that I intend to make my own small error
class (not more than a simple struct) if what I'm asking for help about
can't be done.

It's not very nice to send people to read that much without reading their
question first. Thanks anyway! :)

>> Hi,
>>
>> You can use the Raise method of the error object to raise your own error.
>> I believe the syntax is:
>>
>> Err.Raise(intNumber, "your source", "your description")
>
> complete list of params according to the VBScript Docs:
> object.Raise(number, source, description, helpfile, helpcontext)
> (all params except number are optional)

I'm not interested in raising errors. :)

> the correct call would be:
> object.Raise number, source, description, helpfile, helpcontext
> NO param list () in VBScript Sub calls!

I also (as Richard's example) use paranteses around the arguments. I think
it makes the code easier to read. You have to live with writing Call before
the function/sub name but I prefer it to no paranteses anyway. :)

>> where intNumber is your error number. The error condition is maintained
>> until:
>>
>> Err.Clear
>> On Error GoTo 0
>> On Error Resume Next
>>
>> or a new error is raised.
>>