Discussion:
VB6 Raise Error w/ Custom Description being replaced w/ desc for e
(too old to reply)
Robb
2007-01-26 18:37:01 UTC
Permalink
I'm using VB 6.0, Service Pack 6, on an XP machine.

I'm raising an error with a custom Description in a DLL.

Err.Rasie 106,"MySource","My Custom Description"

When the invoking DLL catches the error the custom description has been
replaced with the default VB description for the error number I raised. And
the Err.Source is blank.

Err.Number = 106
Err.Source = blank
Err.Description = Application-defined or Object-defined error
Any ideas as to why my "custom description" is being lost?
The same code works as I would expect on other XP machines in our shop.
--
Robb
Ken Halter
2007-01-26 18:46:58 UTC
Permalink
Post by Robb
I'm using VB 6.0, Service Pack 6, on an XP machine.
I'm raising an error with a custom Description in a DLL.
Err.Rasie 106,"MySource","My Custom Description"
This seems to work fine... note that you spelled "Raise" wrong above, which
means you're typing code from memory here... which is never a good idea.
It's always best to paste the actual code so we're not spinning our wheels
over a typo.
'====================
Option Explicit

Private Sub Command1_Click()
Dim o As Class1
Set o = New Class1
On Error Resume Next
Call o.TheError
Debug.Print Err.Number
Debug.Print Err.Source
Debug.Print Err.Description
End Sub
'====================
Option Explicit

Public Sub TheError()
Err.Raise 106, "MySource", "My Custom Description"
End Sub
'====================
--
Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
In Loving Memory - http://www.vbsight.com/Remembrance.htm
Bob O`Bob
2007-01-26 19:02:24 UTC
Permalink
Post by Robb
I'm using VB 6.0, Service Pack 6, on an XP machine.
I'm raising an error with a custom Description in a DLL.
Err.Rasie 106,"MySource","My Custom Description"
When the invoking DLL catches the error the custom description has been
replaced with the default VB description for the error number I raised. And
the Err.Source is blank.
Err.Number = 106
Err.Source = blank
Err.Description = Application-defined or Object-defined error
Any ideas as to why my "custom description" is being lost?
You can't pick just any number as if from a hat.

If you simply read the help entry for the Raise method, you'll see.




Bob
--
Robb
2007-01-26 19:28:42 UTC
Permalink
Mispellings aside, I changed my code to

Err.Raise 550, "MySource", "My Custom Description"

(copied and pasted this time) and I'm still getting the same results. I got
550 from Help, it's in the user-defined range. The Error Number gets passed
thru, the custom Description does not.
--
Robb
Post by Bob O`Bob
Post by Robb
I'm using VB 6.0, Service Pack 6, on an XP machine.
I'm raising an error with a custom Description in a DLL.
Err.Rasie 106,"MySource","My Custom Description"
When the invoking DLL catches the error the custom description has been
replaced with the default VB description for the error number I raised. And
the Err.Source is blank.
Err.Number = 106
Err.Source = blank
Err.Description = Application-defined or Object-defined error
Any ideas as to why my "custom description" is being lost?
You can't pick just any number as if from a hat.
If you simply read the help entry for the Raise method, you'll see.
Bob
--
Robert Morley
2007-01-26 19:52:18 UTC
Permalink
Is there anything you can think of that differentiates the XP machine you're
on from other machines where it works? Different language of Windows,
low-level apps & debuggers installed on that one that aren't on the others,
anything of that nature?

Also, rather than using fixed numbers, you should use the vbObjectError
constant (e.g., Err.Raise vbObjectError + 1, "MySource", "My Custom
Description"), just to be absolutely safe. It doesn't sound like it'll make
a difference here, but it's worth a try.

Finally, have a look at this article, it sounds awfully similar to what's
happening to you: http://support.microsoft.com/kb/238082/en-us. Of lesser
relevance, I suspect, there's also
http://support.microsoft.com/kb/255625/en-us.



Rob (with one "b" <grin>)
Post by Robb
Mispellings aside, I changed my code to
Err.Raise 550, "MySource", "My Custom Description"
(copied and pasted this time) and I'm still getting the same results. I got
550 from Help, it's in the user-defined range. The Error Number gets passed
thru, the custom Description does not.
--
Robb
Post by Bob O`Bob
Post by Robb
I'm using VB 6.0, Service Pack 6, on an XP machine.
I'm raising an error with a custom Description in a DLL.
Err.Rasie 106,"MySource","My Custom Description"
When the invoking DLL catches the error the custom description has been
replaced with the default VB description for the error number I raised. And
the Err.Source is blank.
Err.Number = 106
Err.Source = blank
Err.Description = Application-defined or Object-defined error
Any ideas as to why my "custom description" is being lost?
You can't pick just any number as if from a hat.
If you simply read the help entry for the Raise method, you'll see.
Bob
--
Tony Proctor
2007-01-27 11:26:29 UTC
Permalink
According to MSDN, user-defined error numbers should start at
vbObjectError+513 (some very old pages incorrectly say '+512')

The vbObjectError constant is not an error code base. It's actually a bit
mask to apply to the user-defined numbers. VB's runtime reserves the first
512 codes as its own.

Tony Proctor
Post by Robert Morley
Is there anything you can think of that differentiates the XP machine you're
on from other machines where it works? Different language of Windows,
low-level apps & debuggers installed on that one that aren't on the others,
anything of that nature?
Also, rather than using fixed numbers, you should use the vbObjectError
constant (e.g., Err.Raise vbObjectError + 1, "MySource", "My Custom
Description"), just to be absolutely safe. It doesn't sound like it'll make
a difference here, but it's worth a try.
Finally, have a look at this article, it sounds awfully similar to what's
happening to you: http://support.microsoft.com/kb/238082/en-us. Of lesser
relevance, I suspect, there's also
http://support.microsoft.com/kb/255625/en-us.
Rob (with one "b" <grin>)
Post by Robb
Mispellings aside, I changed my code to
Err.Raise 550, "MySource", "My Custom Description"
(copied and pasted this time) and I'm still getting the same results. I got
550 from Help, it's in the user-defined range. The Error Number gets passed
thru, the custom Description does not.
--
Robb
Post by Bob O`Bob
Post by Robb
I'm using VB 6.0, Service Pack 6, on an XP machine.
I'm raising an error with a custom Description in a DLL.
Err.Rasie 106,"MySource","My Custom Description"
When the invoking DLL catches the error the custom description has been
replaced with the default VB description for the error number I
raised.
Post by Robert Morley
Post by Robb
Post by Bob O`Bob
Post by Robb
And
the Err.Source is blank.
Err.Number = 106
Err.Source = blank
Err.Description = Application-defined or Object-defined error
Any ideas as to why my "custom description" is being lost?
You can't pick just any number as if from a hat.
If you simply read the help entry for the Raise method, you'll see.
Bob
--
Robert Morley
2007-01-27 18:38:45 UTC
Permalink
Sorry, you're right, I was forgetting about the 512. That'll teach me to
write messages off the top of my head without checking first. I'm not so
sure about the bit-mask, though...if you're ADDING a number, it's usually
not a bit-mask. If you were OR'ing it, that'd be a different case. But
either way, as long as you're getting your final numbers in the correct
range, that's what matters. :)



Rob
Post by Tony Proctor
According to MSDN, user-defined error numbers should start at
vbObjectError+513 (some very old pages incorrectly say '+512')
The vbObjectError constant is not an error code base. It's actually a bit
mask to apply to the user-defined numbers. VB's runtime reserves the first
512 codes as its own.
Tony Proctor
Post by Robert Morley
Is there anything you can think of that differentiates the XP machine
you're
Post by Robert Morley
on from other machines where it works? Different language of Windows,
low-level apps & debuggers installed on that one that aren't on the
others,
Post by Robert Morley
anything of that nature?
Also, rather than using fixed numbers, you should use the vbObjectError
constant (e.g., Err.Raise vbObjectError + 1, "MySource", "My Custom
Description"), just to be absolutely safe. It doesn't sound like it'll
make
Post by Robert Morley
a difference here, but it's worth a try.
Finally, have a look at this article, it sounds awfully similar to what's
happening to you: http://support.microsoft.com/kb/238082/en-us. Of
lesser
Post by Robert Morley
relevance, I suspect, there's also
http://support.microsoft.com/kb/255625/en-us.
Rob (with one "b" <grin>)
Post by Robb
Mispellings aside, I changed my code to
Err.Raise 550, "MySource", "My Custom Description"
(copied and pasted this time) and I'm still getting the same results.
I
got
550 from Help, it's in the user-defined range. The Error Number gets passed
thru, the custom Description does not.
--
Robb
Post by Bob O`Bob
Post by Robb
I'm using VB 6.0, Service Pack 6, on an XP machine.
I'm raising an error with a custom Description in a DLL.
Err.Rasie 106,"MySource","My Custom Description"
When the invoking DLL catches the error the custom description has
been
Post by Robert Morley
Post by Robb
Post by Bob O`Bob
Post by Robb
replaced with the default VB description for the error number I
raised.
Post by Robert Morley
Post by Robb
Post by Bob O`Bob
Post by Robb
And
the Err.Source is blank.
Err.Number = 106
Err.Source = blank
Err.Description = Application-defined or Object-defined error
Any ideas as to why my "custom description" is being lost?
You can't pick just any number as if from a hat.
If you simply read the help entry for the Raise method, you'll see.
Bob
--
PeterD
2007-01-27 22:18:38 UTC
Permalink
On Sat, 27 Jan 2007 13:38:45 -0500, "Robert Morley"
Post by Robert Morley
Sorry, you're right, I was forgetting about the 512. That'll teach me to
write messages off the top of my head without checking first. I'm not so
sure about the bit-mask, though...if you're ADDING a number, it's usually
not a bit-mask. If you were OR'ing it, that'd be a different case. But
either way, as long as you're getting your final numbers in the correct
range, that's what matters. :)
Rob
Post by Tony Proctor
According to MSDN, user-defined error numbers should start at
vbObjectError+513 (some very old pages incorrectly say '+512')
Adding will work if your error value is between 0 and 3582. the code
would be

vbObjectError + 513 + error_value

Once error_value is > 3582, you need to use a binary OR and not an
addition.

Note: Microsoft's documentation says error_value should be between 513
and 65535. I believe this is incorrect based on looking at the
vbObjectError constant, and therefore I'd suggest using up to 3582 for
best results. Also, MSFT does say 'just add your error value to
vbObjectError... <bg>
Ralph
2007-01-28 15:28:56 UTC
Permalink
<snipped>
Note: Microsoft's documentation says error_value should be between 513
and 65535. I believe this is incorrect based on looking at the
vbObjectError constant, and therefore I'd suggest using up to 3582 for
best results. Also, MSFT does say 'just add your error value to
vbObjectError... <bg>
And does so itself. Here is a snippet from its Class Builder ...

Public Const MyUnhandledError = 9999

'raise an error back to the client
Err.Raise vbObjectError + ErrorNumber, Source, strErrorText

-ralph
<g>

Loading...