473,402 Members | 2,053 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,402 software developers and data experts.

Easy one

Hi
I have a class which goes through its merry life as follows:
* it gets constructed,
* has some properties set,
* has some objects "added" by use of an "Add" method,
* has its "Go" method called,
* does its stuff, perhaps raising a few events,
* gets forgotten about and GCed.

When the "Go" method is called, it checks the parameters. They're not all passed as parameters to the Go method, but set before hand or "Add"ed.
My question is what type of exception should I raise if any of them are invalid, in the following scenarios:

* An object that has been added that is supposed to have sub-objects but doesn't?
* An object that has been added that is supposed to have equal numbers of two different types of subobjects but doesn't (think tables, source columns, dest columns)
* No objects have been added?

Does it actually matter if I use an 'InvalidOperationException' or an 'ArgumentNullException' or is there a better one?
Nov 16 '05 #1
5 946
Patty O'Dors <Pa********@discussions.microsoft.com> wrote:
I have a class which goes through its merry life as follows:
* it gets constructed,
* has some properties set,
* has some objects "added" by use of an "Add" method,
* has its "Go" method called,
* does its stuff, perhaps raising a few events,
* gets forgotten about and GCed.

When the "Go" method is called, it checks the parameters. They're not
all passed as parameters to the Go method, but set before hand or
"Add"ed.
My question is what type of exception should I raise if any of them
are invalid, in the following scenarios:


I think InvalidOperationException is the one to go for unless the
caller has passed a null parameter (which should be non-null) to the
actual method.

The description of InvalidOperationException exactly matches your
problem, I think.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
There's no hard and fast rule that says you have to throw either of these
exceptions. You can extend ApplicationException and create exception
classes that match your exception situation perfectly if the .NET exceptions
don't quite fit the bill.

You could create:
MissingSubObjectException
SubObjectMismatchException
EmptyObjectCollectionException

Those are just a stab in the dark for names feel free to use whatever you
like. :-)

--
C Addison Ritchie, MCSD.NET
Ritch Consulting, Inc.

"Patty O'Dors" <Pa********@discussions.microsoft.com> wrote in message
news:EF**********************************@microsof t.com...
Hi
I have a class which goes through its merry life as follows:
* it gets constructed,
* has some properties set,
* has some objects "added" by use of an "Add" method,
* has its "Go" method called,
* does its stuff, perhaps raising a few events,
* gets forgotten about and GCed.

When the "Go" method is called, it checks the parameters. They're not all passed as parameters to the Go method, but set before hand or "Add"ed. My question is what type of exception should I raise if any of them are invalid, in the following scenarios:
* An object that has been added that is supposed to have sub-objects but doesn't? * An object that has been added that is supposed to have equal numbers of two different types of subobjects but doesn't (think tables, source columns,
dest columns) * No objects have been added?

Does it actually matter if I use an 'InvalidOperationException' or an

'ArgumentNullException' or is there a better one?
Nov 16 '05 #3
That'd be very sweet, but I'd get no actual gain out of doing that work.

I don't need my exceptions to DO anything, other than to be thrown.

Cheers


"C Addison Ritchie" wrote:
There's no hard and fast rule that says you have to throw either of these
exceptions. You can extend ApplicationException and create exception
classes that match your exception situation perfectly if the .NET exceptions
don't quite fit the bill.

You could create:
MissingSubObjectException
SubObjectMismatchException
EmptyObjectCollectionException

Those are just a stab in the dark for names feel free to use whatever you
like. :-)

--
C Addison Ritchie, MCSD.NET
Ritch Consulting, Inc.

"Patty O'Dors" <Pa********@discussions.microsoft.com> wrote in message
news:EF**********************************@microsof t.com...
Hi
I have a class which goes through its merry life as follows:
* it gets constructed,
* has some properties set,
* has some objects "added" by use of an "Add" method,
* has its "Go" method called,
* does its stuff, perhaps raising a few events,
* gets forgotten about and GCed.

When the "Go" method is called, it checks the parameters. They're not all

passed as parameters to the Go method, but set before hand or "Add"ed.
My question is what type of exception should I raise if any of them are

invalid, in the following scenarios:

* An object that has been added that is supposed to have sub-objects but

doesn't?
* An object that has been added that is supposed to have equal numbers of

two different types of subobjects but doesn't (think tables, source columns,
dest columns)
* No objects have been added?

Does it actually matter if I use an 'InvalidOperationException' or an

'ArgumentNullException' or is there a better one?

Nov 16 '05 #4
Patty O'Dors wrote:
That'd be very sweet, but I'd get no actual gain out of doing that
work.


Can't you just throw an ApplicationException then?

--

(O)enone
Nov 16 '05 #5
Oenone <no***@nowhere.com> wrote:
Patty O'Dors wrote:
That'd be very sweet, but I'd get no actual gain out of doing that
work.


Can't you just throw an ApplicationException then?


Why throw that when InvalidOperationException exactly matches the
description of the problem?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Russ Perry Jr | last post by:
I'm using "ID" and "Value" in the generic sense here... Let's say one page I had a <html:select> with a collection like this: <html:options collection="items" property="key"...
0
by: PatchFactory Support | last post by:
Description: Professional and easy-to-use patch building environment that can help you to create instant patch packages for software and file updating. Generated patch packages are small size...
4
by: NBURGAN | last post by:
We are currently searching for a reporting tool with graphics for our end users who are using Oracle's standard edition. We are not using the Oracle's AS. The tool needs to be easy to use and...
19
by: Canon EOS | last post by:
Hi, I am really new in .net and pocket PC development. My background are purely C/C++/VC++. Have developed on Mobile Java for a year and felt completely insecure with it because all codes can...
8
by: Adam Clauss | last post by:
I have a folder containing many subfolders (and subfolders and....) all containing various .cs files. Is there any "easy" way to get them all added to the solution. Preferable would be that the...
2
by: Thomas | last post by:
Hi, I there anybody here that are designing applications with asp.net without html in aspx files? The problem is that aspx files is a dependency, and I would like to avoid having that...
5
by: LedZep | last post by:
What up, All I need to do is enter a last name in a text box, query a MSAccess database and display the name with the corresponding columns. This is no problem, but when there are more than one...
1
by: Mad Scientist Jr | last post by:
can someone explain how to simply populate a grid in .net ? the way i understand it, there is no more msflexgrid, and instead is this new control that has to be tied to a dataset, and it is a real...
13
by: Ghislain Tanguay | last post by:
I have a compiled vb.net app and I want to give the user a choice to launch it from the start line command and pass it a parameter or not. How can I do that in my code? Is it possible? Ex. :...
409
by: jacob navia | last post by:
I am trying to compile as much code in 64 bit mode as possible to test the 64 bit version of lcc-win. The problem appears now that size_t is now 64 bits. Fine. It has to be since there are...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.