Define Custom Errors
Is there a way to define a description text for a custom error code?
E.g., My COM object may return a custom error code vbObjectError + 1000.
If the VB application calls Err.description, I want to it return the custom
text, like "Your files are gone", ant not the generic message "Application
error". Can I do it?
Thanks in advance
Sruli
[371 byte] By [
Sruli] at [2007-11-10 12:19:59]

# 1 Re: Define Custom Errors
"Sruli" <sruli1@hotmail.com> wrote:
>
>Is there a way to define a description text for a custom error code?
>E.g., My COM object may return a custom error code vbObjectError + 1000.
>
>If the VB application calls Err.description, I want to it return the custom
>text, like "Your files are gone", ant not the generic message "Application
>error". Can I do it?
>
>Thanks in advance
>Sruli
at 2007-11-11 18:11:12 >

# 2 Re: Define Custom Errors
Sub errorman()
Dim a As Integer
On Error Resume Next
a = ""
b = Err.Number
c = Err.Description
d = Err.Source
MsgBox "Number " & b & ", " & c & " error.", vbCritical, d
End Sub
at 2007-11-11 18:12:12 >

# 3 Re: Define Custom Errors
You can specify a description, source information (where the error
occurred), and even a pointer to a help file entry when you raise the error:
object.Raise number, source, description, helpfile, helpcontext
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
"Sruli" <sruli1@hotmail.com> wrote in message news:3d3161f0$1@10.1.10.29...
>
> Is there a way to define a description text for a custom error code?
> E.g., My COM object may return a custom error code vbObjectError + 1000.
>
> If the VB application calls Err.description, I want to it return the
custom
> text, like "Your files are gone", ant not the generic message "Application
> error". Can I do it?
>
> Thanks in advance
> Sruli
# 4 Re: Define Custom Errors
This is OK if I raise the error from VB.
However, my VB calls a COM object, which returns a custom error code like
80040777 (vbObjectError + 777). Err.Description just returns the generic
text "Automation error". How can I make it return a custom text, like "All
your files are gone"?
Thanks
Sruli
"Douglas J. Steele" <djsteele@canada.com> wrote:
>You can specify a description, source information (where the error
>occurred), and even a pointer to a help file entry when you raise the error:
>
>object.Raise number, source, description, helpfile, helpcontext
>
>--
>Doug Steele, Microsoft Access MVP
>http://I.Am/DougSteele
>
>
>"Sruli" <sruli1@hotmail.com> wrote in message news:3d3161f0$1@10.1.10.29...
>>
>> Is there a way to define a description text for a custom error code?
>> E.g., My COM object may return a custom error code vbObjectError + 1000.
>>
>> If the VB application calls Err.description, I want to it return the
>custom
>> text, like "Your files are gone", ant not the generic message "Application
>> error". Can I do it?
>>
>> Thanks in advance
>> Sruli
>
>
sruli at 2007-11-11 18:14:15 >

# 5 Re: Define Custom Errors
> This is OK if I raise the error from VB.
> However, my VB calls a COM object, which returns a custom error code like
> 80040777 (vbObjectError + 777). Err.Description just returns the generic
> text "Automation error". How can I make it return a custom text, like "All
> your files are gone"?
Sruli,
Both of your posts make it unclear whether the COM object is being developed
by you, or is provided by a third party. That appears to be why you have
received (what appear to be to you) unsatisfactory answers. Would you like
to clarify?
--
Rob
Wildly Out of Date Excel VBA Programming Stuff:
www.analytical-dynamics.co.uk/
# 6 Re: Define Custom Errors
Rob,
You are right. Sorry for the confusion. The COM object is being developed
by me. It may return both standard errors (e.g., E_FAIL) and custom errors
(HRESULTS) and I want the caller VB application to get the real error description
when it calls Err.Description.
Thanks
Sruli
"Rob Bruce" <rob@analytical-dynamics.co.uk> wrote:
>> This is OK if I raise the error from VB.
>> However, my VB calls a COM object, which returns a custom error code like
>> 80040777 (vbObjectError + 777). Err.Description just returns the generic
>> text "Automation error". How can I make it return a custom text, like
"All
>> your files are gone"?
>
>Sruli,
>
>Both of your posts make it unclear whether the COM object is being developed
>by you, or is provided by a third party. That appears to be why you have
>received (what appear to be to you) unsatisfactory answers. Would you like
>to clarify?
>
>--
>Rob
>
>Wildly Out of Date Excel VBA Programming Stuff:
>www.analytical-dynamics.co.uk/
>
>
Sruli at 2007-11-11 18:16:23 >

# 7 Re: Define Custom Errors
On 15 Jul 2002 01:59:09 -0700, "Sruli" <ganor@softlink.com> wrote:
Rob,
You are right. Sorry for the confusion. The COM object is being developed
by me. It may return both standard errors (e.g., E_FAIL) and custom errors
(HRESULTS) and I want the caller VB application to get the real error description
when it calls Err.Description.
Maybe you could post your code because the Err.Description value should be what you specify in the
Description argument of the Raise method (as Doug mentioned).
Paul ~~~ pclement@ameritech.net
Microsoft MVP (Visual Basic)
# 8 Re: Define Custom Errors
Paul Clement <UseAdddressAtEndofMessage@swspectrum.com> wrote:
>Maybe you could post your code because the Err.Description value should
be what you
>specify in the
>Description argument of the Raise method (as Doug mentioned).
>
>
>Paul ~~~ pclement@ameritech.net
>Microsoft MVP (Visual Basic)
Paul,
I'm afraid that I'm still not clear. I don't use Raise at all. My VB application
calls a COM object which we developed in C++ (not VB). The COM object returns
standard error codes Hresuts (such as E_FAIL) or custom errors. For example,
the COM object may do this:
HRESULT hr = MAKE_HRESULT(1, FACILITY_ITF, 0x777)
return hr; // return custom error 0x80040777
The caller VB detects an error and calls Err.Description, but Err.Description
returns "Automation error" for any custom error. Is there a way I can make
it return the real meaning of each custom error?
Thanks
Sruli
Sruli at 2007-11-11 18:18:18 >

# 9 Re: Define Custom Errors
On 15 Jul 2002 23:37:06 -0700, "Sruli" <ganor@softlink.com> wrote:
Paul Clement <UseAdddressAtEndofMessage@swspectrum.com> wrote:
>Maybe you could post your code because the Err.Description value should
be what you
>specify in the
>Description argument of the Raise method (as Doug mentioned).
>
>
>Paul ~~~ pclement@ameritech.net
>Microsoft MVP (Visual Basic)
Paul,
I'm afraid that I'm still not clear. I don't use Raise at all. My VB application
calls a COM object which we developed in C++ (not VB). The COM object returns
standard error codes Hresuts (such as E_FAIL) or custom errors. For example,
the COM object may do this:
HRESULT hr = MAKE_HRESULT(1, FACILITY_ITF, 0x777)
return hr; // return custom error 0x80040777
The caller VB detects an error and calls Err.Description, but Err.Description
returns "Automation error" for any custom error. Is there a way I can make
it return the real meaning of each custom error?
I'm not a C++ programmer but one of the following may be what you are looking for:
http://msdn.microsoft.com/msdnmag/issues/1000/COM_C/COM_C.asp
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q189134
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnduwam/html/d2dalatl.asp
Paul ~~~ pclement@ameritech.net
Microsoft MVP (Visual Basic)
# 10 Re: Define Custom Errors
Paul Clement <UseAdddressAtEndofMessage@swspectrum.com> wrote:
>I'm not a C++ programmer but one of the following may be what you are looking
for:
>
>http://msdn.microsoft.com/msdnmag/issues/1000/COM_C/COM_C.asp
>http://support.microsoft.com/default.aspx?scid=kb;EN-US;q189134
>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnduwam/html/d2dalatl.asp
>
>
>Paul ~~~ pclement@ameritech.net
>Microsoft MVP (Visual Basic)
Paul,
One of the articles you mentioned really gives a clue how to do it (I wonder
how all my searches have skipped it). The technique is far from being simple,
but at least it's possible. Many thanks.
Sruli Ganor
Sruli at 2007-11-11 18:20:26 >
