Err.Raise - Guidelines

  • Thread starter Thread starter HSalim
  • Start date Start date
H

HSalim

Hi,
Are there any guildelines on how to use Err.Raise?

I'd like to do is to be able to raise a custom error - for example
"cash Balance below Zero" ...

I expect this will help in a couple of ways:
a. Raise error and handle it gracefully -
b. When exiting functions, cleanup before exiting rather than abruptly
exiting function when processing must end

As I understand it,
Err.Raise Number := vbObjectError + 1051, Source:= "SomeClass"
will allow me to use my own set of errors.
Because i am using third party barcode controls in my project, i wamt to
ensure that I don't inadvertently clash with an error number it might be
generating.

In other words, do the Source and the Number make it unique or
is uniqueness solely dependent on the number - in which case, what do I do?

Regards
HS
 
As I understand it,
Err.Raise Number := vbObjectError + 1051, Source:= "SomeClass"
will allow me to use my own set of errors.

Yes... In Access 2K and above, the most convenient way is to define an
enum for the error numbers and list all custom errors in it.

Public Enum MyErrors
Err_Base = vbObjectError or 1051
Err_CashBalanceBelowZero
End Enum

Because i am using third party barcode controls in my project, i wamt
to ensure that I don't inadvertently clash with an error number it
might be generating.

Unless you know the source code, or the 3rd party docs mention the range
they use for their errors, you have no way of making sure that the clash
won't occur. About the only thing you can do if you don't know what range
is being used is to pick a random number for 1501. There are some docs in
msdn.microsoft.com that list the range of COM errors used commonly in
MSFT apps, if I'm not mistaken.
In other words, do the Source and the Number make it unique or
is uniqueness solely dependent on the number - in which case, what do
I do?

So long as you track both source and number in error handling (logging or
msgboxes), you should be fine in terms of uniqueness.

-- Dev
 
Dev,
Thanks for the reply.
Your site is such a great help to all of us. I can't count the number of
times it has helped me. Bless you.

Regards
HS
 
Back
Top