467,081 Members | 961 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,081 developers. It's quick & easy.

custom error numbers

I want to use Err.Raise() method to raise my own exceptions.
Is this the right way of raising my own exceptions ? (i think this is the
only way).

What is the Error number i can safely use, ensuring that it isn't used by
..NET.
Ie, can i use -100 as a error number??
Ie, -100, -101,-102... etc.
I want to konw if .NET uses negative values as error number?
(because i want a specific list of error numbers, to ensure that they are
used & ONLY raised by me in my applications).

Regards,
Paul
Nov 20 '05 #1
  • viewed: 1538
Share:
4 Replies
Paul,

In .NET you can create your own exception class derived from the
system.exception or system.applicationexception class and use it for your
custom error handling.

I do not think Err.Raise along with the error numbers is recommended as it
is a VB6 way where we did not have the structured exception handling.

Best Regards,
Y. Sivaram

"Paul Wilson" <pa**@dummyemailaddress.com> wrote in message
news:ey*************@tk2msftngp13.phx.gbl...
I want to use Err.Raise() method to raise my own exceptions.
Is this the right way of raising my own exceptions ? (i think this is the
only way).

What is the Error number i can safely use, ensuring that it isn't used by
.NET.
Ie, can i use -100 as a error number??
Ie, -100, -101,-102... etc.
I want to konw if .NET uses negative values as error number?
(because i want a specific list of error numbers, to ensure that they are
used & ONLY raised by me in my applications).

Regards,
Paul

Nov 20 '05 #2
Thanx Sivaram.

"Y. Sivaram" <ys******@remove.this.for.spam.yahoo.com> wrote in message
news:O%****************@TK2MSFTNGP09.phx.gbl...
Paul,

In .NET you can create your own exception class derived from the
system.exception or system.applicationexception class and use it for your
custom error handling.

I do not think Err.Raise along with the error numbers is recommended as it is a VB6 way where we did not have the structured exception handling.

Best Regards,
Y. Sivaram

"Paul Wilson" <pa**@dummyemailaddress.com> wrote in message
news:ey*************@tk2msftngp13.phx.gbl...
I want to use Err.Raise() method to raise my own exceptions.
Is this the right way of raising my own exceptions ? (i think this is the only way).

What is the Error number i can safely use, ensuring that it isn't used by .NET.
Ie, can i use -100 as a error number??
Ie, -100, -101,-102... etc.
I want to konw if .NET uses negative values as error number?
(because i want a specific list of error numbers, to ensure that they are used & ONLY raised by me in my applications).

Regards,
Paul


Nov 20 '05 #3
* "Paul Wilson" <pa**@dummyemailaddress.com> scripsit:
I want to use Err.Raise() method to raise my own exceptions.
Is this the right way of raising my own exceptions ? (i think this is the
only way).

What is the Error number i can safely use, ensuring that it isn't used by
.NET.
Ie, can i use -100 as a error number??
Ie, -100, -101,-102... etc.
I want to konw if .NET uses negative values as error number?
(because i want a specific list of error numbers, to ensure that they are
used & ONLY raised by me in my applications).


I would use 'Throw New Exception(...)' to throw simple exceptions. For
extended exceptions, you can inherit from the exception classes and
extend them. Notice that the constructor of 'System.Exception' allows
you to specify an inner exception.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #4
Paul,
In addition to the others comments.

For information on using Throw to "raise errors" and Try/Catch to handle
those errors see:

http://msdn.microsoft.com/library/de...onHandling.asp
Depending on the type of application you are creating, .NET has three
different global exception handlers.

For ASP.NET look at:
System.Web.HttpApplication.Error event
Normally placed in your Global.asax file.

For console applications look at:
System.AppDomain.UnhandledException event
Use AddHandler in your Sub Main.

For Windows Forms look at:
System.Windows.Forms.Application.ThreadException event
Use AddHandler in your Sub Main.

It can be beneficial to combine the above global handlers in your app, as
well as wrap your Sub Main in a try catch itself.

There is an article in the June 2004 MSDN Magazine that shows how to
implement the global exception handling in .NET that explains why & when you
use multiple of the above handlers...

http://msdn.microsoft.com/msdnmag/is...T/default.aspx

For example: In my Windows Forms apps I would have a handler attached to the
Application.ThreadException event, plus a Try/Catch in my Main. The
Try/Catch in Main only catches exceptions if the constructor of the MainForm
raises an exception, the Application.ThreadException handler will catch all
uncaught exceptions from any form/control event handlers.

Hope this helps
Jay
"Paul Wilson" <pa**@dummyemailaddress.com> wrote in message
news:ey*************@tk2msftngp13.phx.gbl...
I want to use Err.Raise() method to raise my own exceptions.
Is this the right way of raising my own exceptions ? (i think this is the
only way).

What is the Error number i can safely use, ensuring that it isn't used by
.NET.
Ie, can i use -100 as a error number??
Ie, -100, -101,-102... etc.
I want to konw if .NET uses negative values as error number?
(because i want a specific list of error numbers, to ensure that they are
used & ONLY raised by me in my applications).

Regards,
Paul

Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

17 posts views Thread by Steve Jorgensen | last post: by
16 posts views Thread by Bret Pehrson | last post: by
6 posts views Thread by Buddy Ackerman | last post: by
4 posts views Thread by Josetta | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.