473,386 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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
4 1800
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Steve Jorgensen | last post by:
If you've ever employed custom error numbers and messages in you programs, you've probably ended up with code similar to what I've ended up with in the past something like... <code> public...
7
by: Steve Jorgensen | last post by:
Here is some code to generate code for raising and getting information about custom errors in an application. Executing the GenerateXyzErrDefs procedure generates the code. <tblXyzError>...
3
by: RC | last post by:
I can't quite grasp the concept of creating custom reports depending upon what options a user picks on a Form. For example, the user clicks on a "Print Reports" button and a Form pops up. On the...
3
by: Rolan | last post by:
I seem to be unable to have a custom error message to appear for Error 10011 (database was unable to append all the data to the table). Each time, the MS Access default error message box appears....
16
by: Bret Pehrson | last post by:
I've converted a non-trivial C++ library to managed, and get the following unhelpful linker error: Assignment.obj : error LNK2022: metadata operation failed (80131195) : Custom attributes are...
1
by: Stephen Adam | last post by:
Hi there, I have written a custom validation control which checks to see of an input field is not empty and contains only numeric data. I was using a regular expression validation control but...
6
by: Buddy Ackerman | last post by:
When trapping unhandled errors in a web page via the Page_Error or Application_Error event procedures is it possible to get the line number on which the error occured? When not using custom error...
4
by: Josetta | last post by:
Can someone point me in the right direction... We have changed our logo and colors and I am redesigning numerous reports. Does anyone know a way to add custom colors whenever I start up my...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.